|
You tried to use old VB6, or VBScript code. Left and Right don't exist in the .NET Framework. Trash this code and try something from a more specific Google[^] search, like "vb.net email validation code"
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
This is a school project. I have to use at least one array and two text files to store information in. The problem I have is that once the app closes, all the information in the array is set 0. Can the information in the array persist on exit? And if not, can the information from the text files that are created fill the array when the app opens?
More background info...
This is a project that requires someone to update inventory information for 10 records in an array. Stock# is the same in both text files and I am totaling one field in one of the text files which updates the array by using the text box on the form.
Thank you,
Larry
|
|
|
|
|
An array only lasts for the lifetime of the program. If you want to persist its data when the program ends, you'll need to write it out to a file.
Same thing when the program starts - the array is empty and you'll need to read the data in from the file and populate your array.
...Steve
1. quod erat demonstrandum
2. "Give a man a fish and you've fed him for a day. Teach him how to fish and you've fed him for life." I read that somewhere once
|
|
|
|
|
Thanks...I think that is where I am confused. I am not sure how to read each line of the txt file to populate the array when the app opens. I am guessing I need to use a For...Next loop but how does I know what line I am on and how to pull each item/column of data and seperate it from the other columns. The array has 5 columns and the text files have 2 columns and 5 columns with one common column.
Is there a function to know how to grab each column per row in the text file...
Lastly this is a school project as I mentioned. Why would you use an array over a database like Access or SQL where it would seem reading and writing data would make more sense.
Thanks in advance!
Larry
-- modified at 10:16 Wednesday 19th April, 2006
|
|
|
|
|
lawrencef14 wrote: Why would you use an array over a database like Access or SQL where it would seem reading and writing data would make more sense.
Last question first - possibly the lecturer/teacher wants you to learn about basic file and array handling. Also for simple applications where not a lot of data is manipulated, storing it in discrete files is fine. When you have a reasonable amount of data or multiple concurrent users of said data, a database of some sort is the way to go.
lawrencef14 wrote: Is there a function to know how to grab each column per row in the text file...
Second question next - yes there is (almost). See next answer.
lawrencef14 wrote: I am not sure how to read each line of the txt file to populate the data. I am guessing I need to use a For...Next loop but how does I know what line I am on and how to pull each item/column of data and seperate it from the other columns. The array has 5 columns and the text files have 2 columns and 5 columns with one common column.
OK, I assume that the files are formatted somewhat like this:
File1: commonvalue1, value2
File2: commonvalue1, value3, value4, value5, value6
Now I won't give exact code here because I'm not on my regular machine and don't have VB etc on this one, but in any case you should be able to lookup the required functions in the VB help files. Here goes... (I found some of this sample code on The Code Project )
Dim dataArray1() As String
Dim fileNumber as Integer
Dim temp As String
fileNumber = FreeFile()
FileOpen(fileNumber, "datafilename.txt", OpenMode.Input, _
OpenAccess.Read)
'EOF() function is used to detect the end of file.
Do While Not EOF(fileNumber)
temp = LineInput(fileNumber)
dataArray1 = Split(temp, ",")
Loop
'Close the file.
FileClose(fileNumber)
That should get you started.
...Steve
1. quod erat demonstrandum
2. "Give a man a fish and you've fed him for a day. Teach him how to fish and you've fed him for life." I read that somewhere once
|
|
|
|
|
Thank you! That is helpful!
|
|
|
|
|
No problems.... I just re-read my last post and there is a bug - it will continually read in each line of data to the same array effectively trashing the previous line of data. Goes to show you I shouldn't try to do this from memory at midnight
In any case I think you now have the basic idea of how to do it so it shouldn't be too hard to modify.
Regards,
...Steve
1. quod erat demonstrandum
2. "Give a man a fish and you've fed him for a day. Teach him how to fish and you've fed him for life." I read that somewhere once
|
|
|
|
|
Yes, what you provided helped a lot and got me to the point where I could fix the issues...
Thanks!!!
Regards!
|
|
|
|
|
Hi,
I've been creating a program in my module that will delete a created SQL server backup files.
Currently, I'm using the so called 'xp_cmdshell' sp to delete those created files. But in the long run, I found out that there's a problem in the deleting these files because the 'xp_cmdshell' coundn't find the specfied file
e.g. master..xp_cmdshell 'del c:\Program Files\Microsoft Sql Server\binn\data\temp00001.bak'.
So, when i used the short path method,
e.g. master..xp_cmdshell 'del C:\PROGRA~1\MI6841~\binn\data\temp00001.bak'
everything works fine. But my problem is, How can i change the long path to short path remotely?
Is there any sp that could help me to translate long path to short path?
By the way, the above code, I just coded it and test it using the SQL Query Analyzer. But my problem is, when i use it in my program.
Im hoping that anyone can help me.
Sincerely,
J.J.
j.j.
|
|
|
|
|
Normally, you wouldn't even put this in your VB code. This is something that you would do from inside a stored procedure or scheduled maintenance job. On top of that, you can also set how far back backups are maintained before being automatically deleted. Soooooo, the question becomes, what are you doing to require you to delete the backup jobs from a VB app by way SQL commands? (I'm assuming this because you posted in the VB.NET Forum...)
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi folks !
In the present code, we use a datagrid as a container to print data from a SQL database. The following gets data (via ODBC) in the SQL database and save it in a DATASET.
Public Function GetDatasetGiveSql(ByVal sqlCmd As String) As DataSet
Dim dataset As New DataSet
odbcCmd.Connection.Close()
odbcCmd = New Odbc.OdbcCommand(sqlCmd, odbcConnection)
odbcAdapt = New Odbc.OdbcDataAdapter(odbcCmd)
odbcCmd.Connection.Open()
odbcAdapt.Fill(dataset)
Return dataset
End Function
Elsewhere in the software, the software builds a query and sends it to the database like this:
dsCommand = sql.GetDatasetGiveSql(cmd)
DataGridCommand.SetDataBinding(dsCommand, "Table")
As you can suspect, dsCommand is a DataSet and DataGridCommand is the DataGrid to update.
Easy to date… OK.
Question:
---------
I want to have control on the background and foreground color of a cell based on some information like any people in this forum. I found many EXAMPLES with DataGridColumnStyle where the idea is to override the Paint method (aka: make a custom datagrid control). Yes, Perfect. I understand it BUT in this case… I DON’T CONTROL ANY COLUMN in the datagrid. It seems that the SetDataBinding() does everything by itself, it is magic.
I did not find HOW to OVERRIDE the Paint() method of this datagrid. Maybe I don’t understand something !
Danny Gilbert, enginneer
Montréal, Canada
-- modified at 13:44 Wednesday 19th April, 2006
|
|
|
|
|
Newbie requiring help to something which is no doubt very simple!
I have written a small application which gathers Company Name data from an Access table. I've also got a ValueMember set up which I am using to display the path to the mdb file used for the Company so that the user can see where the data is located, and it is also allowing me to offer the user a button so that they can open an Explorer window to go straight to the location of the file.
My problem is that if the Company Name field is blank, I want to display some text (other than a blank) in the list box.
The code snippet so far is:
*********************************************
strConnString = "Jet OLEDB:Database Password .... blah, blah ... Provider=""Microsoft.Jet.OLEDB.4.0"";"
Me.OleDbConnection1.ConnectionString = strConnString
Me.OleDbSelectCommand1.CommandText = "SELECT CompanyId, CompanyName, FilePath FROM CompanyDetails WHERE (Version = '1') AND (Deleted = 0) ORDER BY CompanyName"
Me.OleDbSelectCommand1.Connection = Me.OleDbConnection1
OleDbDataAdapter1.Fill(DsCentralDat1)
*********************************************
This works well, and I can see the contents of my database in the listbox - its just that I can't get it to overwrite any blank entries in the listbox (if it finds any) with something which may be more meaningful to the user.
Hope you can help.
|
|
|
|
|
i am just guessing now but try something like this
<br />
if list1.additem = "" then<br />
(insert your code here)<br />
|
|
|
|
|
Thanks for that - but the listbox is, I think, already created and populated during the Fill process. What I'm struggling to do is get it to go and interogate the contents of dataset and build the listbox contents based on the condition that you've mentioned.
I've thought about passing the contents of the database to an array, checking the contents, and passing that to the listbox, but I don't know how to do it.
Any more thoughts?
|
|
|
|
|
nope, sorry. But experiment with some code and it will hit you like a ton of bricks sooner or later
|
|
|
|
|
You could do the following in the query:
SELECT IIf(IsNull([Test]),"Help",[TEST]) AS Expr1, TEST_TABLE.ID
FROM TEST_TABLE;
|
|
|
|
|
OR
strConnString = "Jet OLEDB:Database Password .... blah, blah ... Provider=""Microsoft.Jet.OLEDB.4.0"";"
Me.OleDbConnection1.ConnectionString = strConnString
Me.OleDbSelectCommand1.CommandText = "SELECT CompanyId, CompanyName, FilePath FROM CompanyDetails WHERE (Version = '1') AND (Deleted = 0) ORDER BY CompanyName"
Me.OleDbSelectCommand1.Connection = Me.OleDbConnection1
OleDbDataAdapter1.Fill(DsCentralDat1)
dim row as datarow
for each row in dsCentlralDat1.Tables("TableName").Rows
if isDbNull(row.item("CompanyName") orelse row.item("CompanyName") = "" then
row.item("CompanyName") = "What you want"
end if
next
Me.DataSource = dsCentlralDat1.Tables("TableName")
Me.DisplayMember = "CompanyName"
Me.ValueMember = "CompanyId"
-- modified at 22:46 Tuesday 18th April, 2006
|
|
|
|
|
Thanks - this works brilliantly!!
|
|
|
|
|
i got the numbers 0 to 9 to place in rows and columns for a Sudoku Game, i have managed to code all i need exept for the unique numbers code. All the code is done in VB 6 becuse that is what my crappy school and budget can manage for licenses... >_<
the code for the Sudoku Game (form2 is only a credits window)
Option Explicit<br />
<br />
Private Sub Cmd_cred_Click()<br />
Form2.Visible = True<br />
End Sub<br />
<br />
Private Sub cmd_exit_Click()<br />
End<br />
End Sub<br />
<br />
Private Sub cmd_gen_Click()<br />
Dim a As Integer<br />
For a = 0 To 80<br />
Text1(a) = Int(Rnd * 2)<br />
If Text1(a) = 0 Then<br />
Text1(a) = ""<br />
End If<br />
Next<br />
Dim c As Integer<br />
For c = 0 To 80<br />
If Text1(c).Text = "1" Then<br />
Text1(c) = Int(Rnd * 10)<br />
End If<br />
Next<br />
Dim d As Integer<br />
For d = 0 To 80<br />
If Text1(d).Text = "0" Then<br />
Text1(d) = ""<br />
End If<br />
Next<br />
End Sub<br />
<br />
Private Sub cmd_reset_Click()<br />
Dim b As Integer<br />
For b = 0 To 80<br />
Text1(b) = ""<br />
Next<br />
Form1.BackColor = &HE0E0E0<br />
End Sub<br />
<br />
Private Sub Form_Load()<br />
Form1.BackColor = &HE0E0E0<br />
End Sub<br />
I have been using textboxes wit a control array for this progran
i hope you guys can help me
thanks in advance
|
|
|
|
|
When selecting a number for a square, there are three ways that you need to check for duplicates: In the same horizontal line, in the same vertical line, and in the same 3x3 box.
Still, if you just pick numbers on random you will most of the time end up in a situation where a squre has no possible values at all. Unless you handle this and make the code start over, you will get stuck in an eternal loop.
Creating a correct sudoku puzzle is a bit more complicated than just placing some random numbers. To be correct the puzzle has to have exactly one possible solution, no more, no less.
Perhaps you can find some useful information here: www.setbb.com/sudoku[^].
---
b { font-weight: normal; }
|
|
|
|
|
see, that is why i need the unique numbers code...
i can prolly toy around with the code and make it produce random unique numbers but i do need that code fisrt...
btw, i followed your advice and put a post at setbb
|
|
|
|
|
Well, as I said you have to check horizontally, vertically and in the 3x3 box for duplicates. Start with all numbers 1-9 and loop through the related squares and remove the ones that are used. Then randomly pick one of those left.
By the way, you can download Visual Studio Express versions for free from Microsoft, so it's not a big strain on the budget...
---
b { font-weight: normal; }
|
|
|
|
|
would it not be simpler to put a code string before the randomization process that prohibits doubble numbers for each row, column and 3x3 box?
|
|
|
|
|
A random number is just a floating point number between 0.0 and 1.0. There is no code that prohibits certain ranges for a random number. You have to take that whole range and distribute it equally over the possible numbers.
If all numbers are used except 1, 4, 6 and 7, you distribute the random number range equally over those four numbers:
0.00 <= Rnd < 0.25 --> 1
0.25 <= Rnd < 0.50 --> 4
0.50 <= Rnd < 0.75 --> 6
0.75 <= Rnd < 1.00 --> 7
The easiest way of doing that is of course to pick a random number between 0 and 3, and translate to the available numbers.
---
b { font-weight: normal; }
|
|
|
|
|
Hi Guys!! How do i come to know through code whether my Application is connected to the Internet or not. I want to display in the StatusStrip whether an Internet Conection is detected or not. How do i do this in VB.NET!! Thanx in Advanced!!
Devraj Raut!!!
|
|
|
|