retrieving data files

3rdElement
06-08-2005, 04:05 PM
I don't really know how to explain it in words but I was hoping you guys can help.

What I am trying to do is create simulation environment, and trying to see if I could display letter while program is running. Don't worry about how I can get VB running interconnect with program, I had a success in that area. All I
I wanted to know if its possible to retrieve data files from program and have it display in picbox or captionbox on the form? Allow me give a simple demostration as an example.

File saved as AWAY.DAT in data file--> from program




----------------------------------------------------------------------00C 37.203178-107.869194 6683 ;Animas
00CA 35.350525-116.888367 3038 ;Goldstone (gts)
00CO 40.622204-104.344398 4829 ;Cass Field
00FA 28.645548 -82.218971 52 ;Grass Patch
----------------------------------------------------------------------

VB6 FORM MAIN
________________________________________________________________
| .____________
| |Animas |
| |___________ | <--Picture/Caption box |
| .____________ |
| |Golstone(gts) | |
| |___________ | |
| .____________
| |Cass Field |
| |___________ |
| .____________
| |Grass Patch |
| |___________|

________________________________________________________________

It will not display anything unless program begain to initialize. Once it initialize, the datas coming directly folder along with program will display the letter context inside or on the picture/caption box.
If it's possible would there be any code examples? or some sources that may provid imformation similar to what I am looking for.

Let me know

ElderKnight
06-09-2005, 06:47 AM
For debug purposes, I often add a picture box or a list box to my program, and dump the results of a file that I've just written so that I can check it out swiftly.

Dim strOneLine as String
Open "ProgOutput.TXT" for Input as #99
Do until EOF(99)
Line Input #99, strOneLine
picDebug.Print strOneLine
' or: lstDebug.AddItem strOneLine
Loop
Close 99

Is that what you were asking about?

The list box is okay when you're only interested in the text. With the picture box, you can see the effect of tabs, chr$(), spc(), fonts, colors, etc. However, the list box will scroll for you, so it may be preferable.

3rdElement
06-09-2005, 05:22 PM
Dim strOneLine As String
Open "Away.DAT" For Input As #99
Do Until EOF(99)
Line Input #99, strOneLine
picDebug.Print strOneLine
' or: lstDebug.AddItem strOneLine
Loop
Close 99

The code above... came up with... "runtime error '53' file not found" and I do not know why...

Is that what you were asking about?

Okay... Let me rephrase that, and explain you more CLEARLY.(at my best)

I have created data file called Away.DAT and in this file, it contains all of listing with state city and name which look like this:

Honolou, Hawaii
Duluth, Minnesota
Washington,DC
Miami,Florida
Chicago, Illinois
Indianapolis, Indiana
Dallas, Texas
Phoenix, Arizona
Los Angeles, California
New York City, New York

And in VB form layout it has two textboxes. Textbox1 (state name) and textbox2 (search field). So my objective is to build a code that I could type in text box i.e. 'New York' and then maybe hit enter key or click on command button to initialize search, and when it starts it will be searching for matched name 'New York' from the list inside away.dat file once it found, only one strip from the list will appears on textbox 2 labeled 'New York City, New York. Then I do find it match. Otherwise, If I type in Virginia on textbox one, search it.. then nothing will show up in the textbox 2 because it doesn't have any matched name from the list inside Away.dat. I hope I explain it clearly. If not, take a look at attached picture.

I don't really know how it works it, or how I can input it But I was doing some logical thoughts with how or is it possible questions? for an example... would it be possible for vb program with proper assigned code do search on only one .dat file and select one precise word based on what is typed in from all of lists? or do i really need to set .dat file indivually such as. NY.DAT, IND.DAT, ILL.DAT, and each inside .dat will display only specific state such as NY.DAT--> New York City,New York, IND.DAT--> Indianapolis, Indiana, and etc?
I was even wondering about how can code work if I just type charaters inside textbox and get it searched through to find matched file? Alternatively I could do if statement but still wondering how for example
Let say it's a logical code not actual one.

If Textbox1 = New York then
Else
Open "C:\NY.DAT " For Input As #1
endif

If Text1.SelStart = 0 Then
MsgBox "search Not Found!", vbExclamation

Or something like that.... Any ideas??

Don't forget to look at attached file.

gfleming
06-09-2005, 11:33 PM
Try this,

After entering search value, then activating the search (using command button maybe)


Private Sub cmdSearch_Click()

Dim blnFound As Boolean
Dim strNewLine As String

blnFound = False
txtSearchResult.Text = "No Match"

Open App.Path & "\away.dat" For Input As #1

Do Until EOF(1) Or blnFound
Line Input #1, strNewLine
If InStr(UCase(strNewLine), UCase(txtSearch.Text)) > 0 Then
txtSearchResult.Text = Right(strNewLine, Len(strNewLine) - InStr(strNewLine, ",") - 1)
blnFound = True
End If
Loop

Close #1

End Sub


This code assumes the values stored on each line of the .dat file are separated by ",".

The string comparison is not case sensative.

The search loop will be exited as soon as a match is found (or it gets to the end of the file).

Dim strOneLine As String
Open "Away.DAT" For Input As #99
Do Until EOF(99)
Line Input #99, strOneLine
picDebug.Print strOneLine
' or: lstDebug.AddItem strOneLine
Loop
Close 99

The code above... came up with... "runtime error '53' file not found" and I do not know why...



Okay... Let me rephrase that, and explain you more CLEARLY.(at my best)

I have created data file called Away.DAT and in this file, it contains all of listing with state city and name which look like this:

Honolou, Hawaii
Duluth, Minnesota
Washington,DC
Miami,Florida
Chicago, Illinois
Indianapolis, Indiana
Dallas, Texas
Phoenix, Arizona
Los Angeles, California
New York City, New York

And in VB form layout it has two textboxes. Textbox1 (state name) and textbox2 (search field). So my objective is to build a code that I could type in text box i.e. 'New York' and then maybe hit enter key or click on command button to initialize search, and when it starts it will be searching for matched name 'New York' from the list inside away.dat file once it found, only one strip from the list will appears on textbox 2 labeled 'New York City, New York. Then I do find it match. Otherwise, If I type in Virginia on textbox one, search it.. then nothing will show up in the textbox 2 because it doesn't have any matched name from the list inside Away.dat. I hope I explain it clearly. If not, take a look at attached picture.

I don't really know how it works it, or how I can input it But I was doing some logical thoughts with how or is it possible questions? for an example... would it be possible for vb program with proper assigned code do search on only one .dat file and select one precise word based on what is typed in from all of lists? or do i really need to set .dat file indivually such as. NY.DAT, IND.DAT, ILL.DAT, and each inside .dat will display only specific state such as NY.DAT--> New York City,New York, IND.DAT--> Indianapolis, Indiana, and etc?
I was even wondering about how can code work if I just type charaters inside textbox and get it searched through to find matched file? Alternatively I could do if statement but still wondering how for example
Let say it's a logical code not actual one.

If Textbox1 = New York then
Else
Open "C:\NY.DAT " For Input As #1
endif

If Text1.SelStart = 0 Then
MsgBox "search Not Found!", vbExclamation

Or something like that.... Any ideas??

Don't forget to look at attached file.

3rdElement
06-10-2005, 01:35 AM
This code assumes the values stored on each line of the .dat file are separated by ",".

Value of each line? I am not sure I know anything about value... can you demonstrate example of values stored on each line?

3rdElement
06-10-2005, 03:21 AM
Code seem to be working.. Almost but I get an error:

First error i:
Runtime error '53' files not found.

That's because: Open App.Path & "\away.dat" For Input As #1

I added 'C' to this string Open App.Path & "C\away.dat" For Input As #1


Then I get secondt error:
Runtime error '52' bad file name or number

And it is on same string: Open App.Path & "\away.dat" For Input As #1

What may be wrong? Assume it has something to do with my .dat file inside my away.dat file it is exactly how I wrote:

Honolou, Hawaii
Duluth, Minnesota
Washington,DC
Miami,Florida
Chicago, Illinois
Indianapolis, Indiana
Dallas, Texas
Phoenix, Arizona
Los Angeles, California
New York City, New York

is this how it should look? or do I need to add some value, requirements in .dat file? if so help me, show me what it should look like.

3rdElement
06-10-2005, 03:24 AM
Sorry, forgot to add 'C'... rephrasing that...

Then I get second error:
Runtime error '52' bad file name or number

And it is on same string: Open App.Path & "c:\away.dat" For Input As #1

ElderKnight
06-10-2005, 06:41 AM
Well, you can't have the drive name ("C:") in the middle of the path. The system will set App.Path to the directory from which the program was run, maybe "C:\Program Files\MyProg" or "C:\VB\Applications" or something.

When you append the file name to App.Path, you ought to have the full file name for use in the Open statement (you have to take care not to lose the backslash (\) and not to end up with two of them).

You should probably put a breakpoint on the Open statement so that you can check the full file name (in the direct window, enter:
Print App.Path & "\away.dat"
) prior to its being used. That, or print out the filename or put it in a MsgBox.

Diurnal
06-10-2005, 06:42 AM
If the file resides in the same directory as your program, use :

Open App.Path & "\Away.dat" For Input As #1

If the file is not in the application directory, then use the qualified path:

Open "C:\Away.dat" For Input As #1

Use one method or the other. Combining them is telling the system to open a file in a path does not exist ie:

Path to open = "C:\Program Files\My Cool Program Folder\C:\Away.dat"

In this path there are two root directories which is not possible and it is pointing to a file through a path that does not exist.

3rdElement
06-10-2005, 06:31 PM
Yes! got it working.... Thank you guys you are a big help.... one more thing, would you by any chance explain me each what each string of code does so I can write it down on note for my future reference? I want to be able to learn more cool stuffs in VB. Once again Thanks

gfleming
06-12-2005, 11:47 AM
I am not sure what code you ended up with, but mine works as follows:


Private Sub cmdSearch_Click()

'defines variables,
'Boolen is for variables that only have two values (true of false)
'String is for variables containg text
Dim blnFound As Boolean
Dim strNewLine As String

'set blnFound to false so that it can later be used
'to check if a match was found (that is, it remains
'false until the entered text is found in the input
'file, then blnFound is assigned true)
blnFound = False

'sets the default answer.
'This means that the answer will always be
' "No Match", unless a match is found
'(at which point you then change txtSearchResult.Text ).
txtSearchResult.Text = "No Match"

'open - open the following file.
'App.Path - holds the value of the application path of
' the VB program you are running.
'away.dat - the name of the file to be opened
'For Input - reason for onpening file
'As #1 - assigns #1 as the name of the file
' to be used in the code (we could also
' use #2, #3 etc
'App.Path is a bit redundant. If the file to be opened is in the same
'folder as the application then we can use:
'
'Open "away.dat" For Input As #1
'
'if it is in any other folder, you need the full extesion name (or refer it in
'relative reference to the application file.
'
'other file uses are:
'
'For Output - allows you to output to a file, when the file is opened
' all data presently in the file is deleted.
'
'For Append - same as above, only previous data is not lost.

Open App.Path & "\away.dat" For Input As #1

'do the folowing tasks repeatedly until either you are at the
'end of the file, or you find the matching text
'
'EOF(1) - end of the file (last line) known as #1

Do Until EOF(1) Or blnFound
'take the line of text you are presently looking at (in #1)
'and assign it to the variable strNewLine (declared at the top)
Line Input #1, strNewLine
'
'InStr(string1,string2) - function that looks at the first string to see
' if it contains the second string. If it does,
' then it returns the starting position of the
' second string, else it returns 0
'
'UCase(string) - sets all character values of the string to upper case.
'
'when comaring strings, make them both UCase or LCase
'vb will read 'My Words' as different from 'my words', so IF you
'need the comparison to be case sensitive dont use UCase
'
'If the search string is found (> 0)
If InStr(UCase(strNewLine), UCase(txtSearch.Text)) > 0 Then
'result is everything to the right of the space after "," in strNewLine
'(if this line is never executed the result remains "No Match"
'Right(String, X) - returns the last X charactors of String
'Len(String) - number of charactors in String
'
txtSearchResult.Text = Right(strNewLine, Len(strNewLine) - InStr(strNewLine, ",") - 1)
'
'Let program know that the matching string has been found.
'When it starts the loop again, it will look to see if the match
'has been found before deciding whether or not to redo the loop.
blnFound = True
End If
Loop
'
'Everytime you open a file, you need to close it.
Close #1

End Sub



Yes! got it working.... Thank you guys you are a big help.... one more thing, would you by any chance explain me each what each string of code does so I can write it down on note for my future reference? I want to be able to learn more cool stuffs in VB. Once again Thanks

3rdElement
06-12-2005, 02:31 PM
Thank you gfleming helping me out understanding all of these details, that helps :) I truly appreciate it.

3rdElement
06-12-2005, 04:11 PM
Oh one more thing... I want to confirm my understanding about input string.
with #1, #2, and #3

in .dat file

Mike Smith, 06-15-80, Lubbock Texas.

(On form)

Name: <--Label1
Mike Smith <--Textbox1 (As Input #1 in string code)

DOB (mm\dd\yy) <--Label2
06-15-80 <--Textbox2 (As Input # 2 in string code)

Place of Birth (City State): <--Label3
Lubbock Texas <-- Textbox3 (As Input # 3 in string code)

Hello Mike! <--Label4 (if match found)


Please tell me I understand it correct?

gfleming
06-15-2005, 06:19 PM
No you don't understand, but what you have written here is different from your orriginal thread.

Please explain what you are trying to do, then I can explain how to do it.

Oh one more thing... I want to confirm my understanding about input string.
with #1, #2, and #3

in .dat file

Mike Smith, 06-15-80, Lubbock Texas.

(On form)

Name: <--Label1
Mike Smith <--Textbox1 (As Input #1 in string code)

DOB (mm\dd\yy) <--Label2
06-15-80 <--Textbox2 (As Input # 2 in string code)

Place of Birth (City State): <--Label3
Lubbock Texas <-- Textbox3 (As Input # 3 in string code)

Hello Mike! <--Label4 (if match found)


Please tell me I understand it correct?

3rdElement
06-15-2005, 06:38 PM
No you don't understand, but what you have written here is different from your orriginal thread.

Please explain what you are trying to do, then I can explain how to do it.

Well... my written is differ from the original thread is because I am trying to give you clear perpective on what i m trying to explain.


hmm.. Okay let me rephrase it... I create data information that contain more than 1 information in same string saving as "away.dat":

St.Paul, Minnesota, North, Lake, Fishing

Then run a search engine.. i wanted to type Minnesota... and once it found a match... all information that filled in one string from away.dat will appears in 4 text boxes separately;

VB Form

State Name: <----Label1
Minnesota <----After typing in text box

Captial City Name: <-----Label2
St.Paul <---Search found in text box

Famous Place: <---Label3
Lake <----Search found in text box

Popular Events: <-----Label4
Fishing <-----Search found in text box

would or could the original code that you gave me do that?

gfleming
06-15-2005, 07:36 PM
Private Sub cmdSearch_Click()

Dim i As Integer
Dim strNewLine As String
ReDim Result(0) As String

Open App.Path & "\away.dat" For Input As #1

Do Until EOF(1)
Line Input #1, strNewLine
If InStr(UCase(strNewLine), UCase(txtSearch.Text)) > 0 Then
'split function takes a string and splits it based on a delimeter
'the resulting strings are placed in a zero array
Result = Split(strNewLine, ",")
txtCapital = Result(0)
txtState = Result(1) 'this line is not needed
txtPlace = Result(2)
txtEvent = Result(3)
End If
Loop
Close #1

End Sub





Well... my written is differ from the original thread is because I am trying to give you clear perpective on what i m trying to explain.


hmm.. Okay let me rephrase it... I create data information that contain more than 1 information in same string saving as "away.dat":

St.Paul, Minnesota, North, Lake, Fishing

Then run a search engine.. i wanted to type Minnesota... and once it found a match... all information that filled in one string from away.dat will appears in 4 text boxes separately;

VB Form

State Name: <----Label1
Minnesota <----After typing in text box

Captial City Name: <-----Label2
St.Paul <---Search found in text box

Famous Place: <---Label3
Lake <----Search found in text box

Popular Events: <-----Label4
Fishing <-----Search found in text box

would or could the original code that you gave me do that?

3rdElement
06-15-2005, 08:04 PM
I Tried and it worked.. Look great... thank you so much

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum