|
Why does this have the stench of homework around it?
Your constantly picking two random numbers and seeing if one divides evenly into the other. If it fails, you're picking two more, and so on, and so on... The chances of the RNG picking two number that divide evenly into each other are pretty low, so of course, it takes a long time to find two numbers that match your criteria.
I have no idea what your homework assignment is, but, how about picking a random number for one and then contantly trying random numbers to divide into it. In other words, pick a random number for label1, then in a do loop, keep picking random numbers until you find one that divides evenly into the first.
This will have the effect of trying to hit a stationary target, instead of a moving one.
There are other, much better ways of doing this, but, then again, it's your homework, isn't it?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
What you are saying makes more sense. Thanks. Really, it isn't a homework problem. I am doing a flashcard program for my daughter. She is learning how to add and subtract and I already have those done along with multiplication so I figured I would go ahead and put division in there. This is my first project. I am trying to teach myself how to use vb.net.
|
|
|
|
|
OK. If you want two numbers that are evenly divisible and do it quickly, generate two random numbers, put one of those numbers into one of the textbox's. Then, multiply the two numbers together and put the result in the other textbox. This will quickly give you two numbers that are evenly divisible.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
does anyone of you know how to get the length of a string array?
My code looks like this
<br />
mystring = ActiveDocument.Paragraphs(index)<br />
mydata = Split(mystring, " ")<br />
So in the beginning I do not know the size of the array. But I do need to know if the word I am searching for, is in this array. Therefor I have to parse the array to search it. But if I do not know the upper limit, this causes a "out of bounds" error. So I do need the upper limit to avoid the error to be thrown.
Could anyone please tell me how to get the length so I could do the following (in VBA!) ?
<br />
For i = 0 to upperlimit<br />
if mydata(i) = mysearchstring then<br />
do something<br />
end if<br />
Next
Thanks!
Stephan.
|
|
|
|
|
Try UBound(mydata,1)
An optimist's glass is half full.
A pesimist's glass is half empty.
An engineer goes and gets the right size glass.
|
|
|
|
|
thanks, it works!
Stephan.
|
|
|
|
|
There are at least 3 ways to do what you want:
1. As already mentioned, use ubound. ubound is a vb only feature and is convenient because it returns the upper bound of the array which is usefull for loops.
2. mydata.Length basically returns the count of array items. This available in any language of .net. It is less convenient for loops because you must subtract 1 from it.
3. For Each loop:
For Each str As String In MyData
'Do Something
Next
You don't have to know the array bounds to loop through the items.
|
|
|
|
|
I'm a novice at code writing (newbie is something my kids would call it) and need some advice.
I need to write some code that enables me to access and manipulate data from a database object. This code has to validate the data away from the database. I would personally like to use an object that has methods that read and write to the database and properties that manage validation. This would make life easier when using the properties or field values with other objects. The problem with business objects is the time it takes to create the object.
If I want to run a datagrid based on a collection of business objects it takes too long to create the object collection (for example sales orders). Linking the datagrid to a dataview and using a datatable to hold the values is far quicker. The business objects method appears to provide a better method of creating sales orders without access to the database using a localised copy of any necessary data (part codes, etc).
One other point, the database is provided by a third party and I'm writing an additional interface (this is allowed and part of the software contract) that provides additional facilities. So that the interface isn't restricted by hard coding I have created configuration files that identify table field names, label descriptions, table column headers, table widths, column orders and properties used to create a tab control interface such as top,left,width (for the placement of text boxes) and group properties (used to create different tab pages). I've done this because I'm just a little concerned that if I leave the company they won't be able to change any of the intferface.
I know I can't avoid hard coding validation but the data screens can be configured without hard coding. I currently use a tab deliminated file (so we can use commas in field names or sql commands) but will propbably change to xml as excel is rubbish for tab deliminated (places double quatation marks without asking) and I wan't a columned interface for users to read/write to the configuration files.
What is everyone's thoughts on this. Time to retrieve and refresh data is important. The ability to travel half way around the world and create a 'dummy' sales order to enter into the database is also equally as important.
Any advice would be gratefully appreciated.
Fawxes
An optimist's glass is half full.
A pesimist's glass is half empty.
An engineer goes and gets the right size glass.
|
|
|
|
|
System.IO.IOException: Insufficient system resources exist to complete the requested service.
at System.IO.__Error.WinIOError(Int32 errorCode, String str)
at System.IO.__Error.WinIOError()
at System.IO.FileInfo.MoveTo(String destFileName)
at SPC_Polish_Services.CommonFunction.MoveFile(String oldPath, String fileName, String subDir, Int32 fid, String type)
I'm trying to movefile a file in my windows service.
I've no idea at all how to solve this problem..
please help me...thanks~
sayhigh_soon
|
|
|
|
|
We need to see the code that your using to move the file. The error you posted isn't supplying enough information. Also, is the service running under the Local System account, or an account created for this service?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
thanks for your reply.
The service is running under local system account.
<br />
'********************************************************************<br />
' Process: MoveFile<br />
' Input: oldPath, fileName, subDir ['Save'|'Error'], fid, Type ['NEW' | 'UV']<br />
' Output: Move file to destination folder<br />
'********************************************************************<br />
Public Sub MoveFile(ByVal oldPath As String, ByVal fileName As String, ByVal subDir As String, ByVal fid As Integer, ByVal type As String)<br />
Dim Conn As New SqlConnection(strConn)<br />
Dim fi As New FileInfo(oldPath)<br />
Dim targetDir As String = ConfigurationSettings.AppSettings("dirPath" & type).Trim & "\" & subDir<br />
Dim newPath As String = targetDir & "\" & fileName<br />
Dim tblStatusName As String = ConfigurationSettings.AppSettings("tblStatusName" & type).Trim<br />
Dim errorMsg As String<br />
Dim attempt As Integer = 0<br />
<br />
If File.Exists(newPath) Then<br />
'Extra: To ensure delete only normal file (destination folder)<br />
File.SetAttributes(newPath, FileAttributes.Normal)<br />
File.Delete(newPath)<br />
End If<br />
<br />
'Try for another 5 attempts if meet "it is being used by another process" error<br />
Do<br />
Try<br />
'Set the Read-Only file (source folder) to normal file before move to destination folder<br />
If File.Exists(oldPath) Then<br />
File.SetAttributes(oldPath, FileAttributes.Normal)<br />
<br />
'If target folder not exist then create the folder<br />
If Not Directory.Exists(targetDir) Then<br />
Directory.CreateDirectory(targetDir)<br />
End If<br />
fi.MoveTo(newPath)<br />
<br />
'Log<br />
EvtLog("File successfully moved to " & newPath, localhost.EventLogEntryType.Information, 5)<br />
DBLog(logTableName, type, oldPath, "File successfully moved to " & newPath, logName, logSource)<br />
End If<br />
<br />
GoTo final<br />
<br />
Catch ex As Exception<br />
errorMsg = ex.ToString<br />
<br />
If InStr(errorMsg, "it is being used by another process") <> 0 Then<br />
<br />
If attempt <= 5 Then<br />
EvtLog("*** Sub MoveFile Attempt " & attempt & " fail(" & oldPath & "): " & ex.ToString, localhost.EventLogEntryType.Error, 15)<br />
DBLog(logTableName, type, oldPath, "Sub MoveFile Attempt " & attempt & " fail: " & ex.ToString, logName, logSource)<br />
<br />
attempt += 1<br />
<br />
'Wait for 30 seconds before go for another attempt<br />
Thread.CurrentThread.Sleep(30000)<br />
End If<br />
<br />
Else<br />
GoTo email<br />
End If<br />
End Try<br />
Loop While attempt <= 5<br />
.....<br />
.....<br />
.....<br />
End Sub<br />
sayhigh
|
|
|
|
|
A little convoluted, don't you think?
First, strip out all the logging code and get it down to just what is essential for making 5 attempts at moving the file.
Get rid of this line, you never use the object:
Dim Conn As New SqlConnection(strConn)
Rewrite the code and NEVER use "Goto"'s.
Get rid of the "fid" parameter in your method header, you never use it.
Get rid of the "type" parameter in your method header. All you use it for is logging information, which is not an essential part of what this function does.
KEEP IT SIMPLE! Get it down to a working function first, then add the logging code you need.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I am getting a similar error. I have a simple windows app that copies a local file to a unc path. The application works fine on 5 out of 6 win2003 servers. on the 6th one it throws an error similar to the one shown above. So far i can't find any setup differences between the servers.
here is the function i have that copies the file. pretty straightforward.
public static string SaveFile(string destinationPath, byte[] file, string fileName, bool overwriteExisting)
{
string returnFileName = fileName;
if (overwriteExisting == true)
{
using (FileStream fStream = new FileStream(destinationPath + @"\" + returnFileName, FileMode.Create, FileAccess.Write))
{
fStream.Write(file, 0, file.GetLength(0));
fStream.Seek(0, SeekOrigin.Begin);
}
}
else
{
using (FileStream fStream = new FileStream(destinationPath + @"\" + returnFileName, FileMode.CreateNew, FileAccess.Write))
{
fStream.Write(file, 0, file.GetLength(0));
fStream.Seek(0, SeekOrigin.Begin);
}
}
return returnFileName;
}
Kirk Quinbar
Zywave, Inc.
|
|
|
|
|
HI Everybody!
I just want to know what is major difference between a Dataset and reordset.
Does recordset object is supported in VB.NET
Please help me in finding the answer
|
|
|
|
|
A recordset is just that, a set of records in a single table. A DataSet can represent multiple tables, with varying records, and relationships between those tables.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hai ,
the major difference is ADO recordset is Connectted DataAccess and a single dimensionsional array to hold datas
in 1d array so if you wanna navigate through data ,u need to use movenext,movelast method,BUt in .net
is disconnected data access ,The datas are stored in datatable in multidimensionsal array like your database table.
so you can navigate the record via simple methods.and dataset is the in memory representation that can hold many tables.
you can make relationship bettween table and dataset is in XSD for so you can send through network without marshelling.
and you can use ADO recordset objects in .Net with the refernce of MsADo.dll files For more info go to MSDN APril 2003
Ishak
Programmer analyst
ITI KSA
|
|
|
|
|
Dear Visual Basic & Access Experts
In my application program, I have a Access (version xp) form that calls a update event handler. In this handler I need to know if the user has clicked on the "Close" button of the form. What VBasic codes do we use to check what action triggers off the the chain of events that lead up to the update event & onwards? In particular I am interested to to check if the triggering event is the clicking of the "Close" button of the form; if so I will then write some code to handle this particular case. I tried to handle this via Close event handler but since it comes after the "Update" event, it does not work.
Please help...Cheers! Michael
|
|
|
|
|
FuzMic wrote:
In this handler I need to know if the user has clicked on the "Close" button of the form.
There is no way to trace back to see what triggered the update. Since the Close event of the form fires AFTER your Update event, you can't set a flag that specifies the form is closing, so there is no way for your code to know the difference, and frankly, in the grand scheme of things, the Update event shouldn't care if the form is closing or not.
Why do you need to change the functionality of the Update on Form Close?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
It sounds like you are trying the round-a-bout way of doing things.
Could you do what you want by having separate 'OK' and 'Cancel' buttons? With a cancel button you can prevent the Update, if that's what you're looking to do.
FuzMic wrote:
In particular I am interested to to check if the triggering event is the clicking of the "Close" button of the form
If you just want to know if the close button has been clicked when the Update event occurs, you could define a module-level boolean such as closeClicked initialized to FALSE .
In the Close button's OnClick handler, set closeClicked = TRUE . Then, in your OnUpdate handler, you can check the value of closeClicked to see if the button has been pushed.
Just make sure you set closeClicked = TRUE before the docmd.close acForm, me.name command.
I wouldn't go so far as to call this method 'sloppy', but I would think there should be a more graceful way of accomplishing your goal.
|
|
|
|
|
Dear Mike the Red from Fuzzy Mike
Perhaps my message was not clear; I am not referring to a Close "Command" button that is placed on a form. I am referring to the Form Close button that comes inherent with the form on top right hand corner; in which case, how can a boolean var be flagged on clicking since there is no such event handler within the form to set it up ... UNLESS ... it is via the Window OS???.
Come what say u; Thanks & Cheers!.
Dear Dave Kreskowiak
You wrote: Why do you need to change the functionality of the Update on Form
Close?
I am using the Update event handler to do various checks such as check for duplicate, empty fields, etc. Thus if a user click on the Form Close, the form will go into the update event if the form is dirtied. At this point if the test failed, a message tells user the option to Undo or to make corrections. However since the user want to close the form, I must drop the correction option and change the message.
By the way how do Window OS handle a form close event?
Thanks & Cheers!
|
|
|
|
|
I need to read values from an excel spreadsheet into a string array in VB.NET.
I can read the cells with no problems if I take the values into single dimensional variables, but I get an error when I try to read into an array.
The code fragment is:
Dim filename As String
filename = "c:\pass\userlist.csv"
Dim intRows As Integer
Dim fqn() as string
Dim r, i As Integer
' Open the Workbook in excel
Dim xlApp As Excel.Application
xlApp = CType(CreateObject("Excel.Application"), Excel.Application)
xlApp.Visible = False
Dim xlWB As Excel.Workbook
Dim xls As Excel.Worksheet
xlWB = CType(xlApp.Workbooks.Open(filename), Excel.Workbook)
xls = CType(xlWB.Worksheets(1), Excel.Worksheet)
intRows = xls.UsedRange.Rows.Count
num = intRows - 1
' Scroll through all the rows and columns retrieving values.
i = 1
For i = 0 To num
fqn(i) = CType(xls.Cells(r, 1), Excel.Range).Text
Next
xlWB.Close(False)
xlApp.Quit()
xls = Nothing
xlWB = Nothing
xlApp = Nothing
The error generated is:
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll
Additional information: Exception from HRESULT: 0x800A03EC.
I have added the Excel library reference (11.0)
Any help would be appreciated
Greg S
|
|
|
|
|
I am trying to display nicely formatted text (as in RTF)
on a graphical background.
The standard RichTextBox control doesn't allow transparency,
so I could overlay a graphics, not does it allow me to set
a background image.
Could anybody tell me how I could get either of these to work,
or alternatively if there is a way to draw the formatted text
from a RichTextBox control on a picture or graphic?
Thanks,
Tom Verkaaik
|
|
|
|
|
I need to connect a scanner(hardware device) programmatically to my vb.net applicaion.The cloth or paper that is being scanned with the scanner should directly come in the picture box in vb.net.Can anyone please help me with it? its very important.If you have an answer then please mail me at avanti_dharkar@rediffmail.com.
|
|
|
|
|
You can use the ImgScan.ocx.
It exists from win 95 to windows 2000. Windows xp doesn't supply this control.
Then you can use its events to direct the scanned image to the picture box.
You can connect any ISIS or Twain scanners to it.
|
|
|
|
|
Thanks, i will try using this
|
|
|
|
|