Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 07-24-2002, 11:19 PM   #1
Member (9 bit)
 
muTe's Avatar
 
Join Date: Jan 2002
Location: Quebec, Canada
Posts: 426
how do I retreice data from a file?!

Hi,

I've make a little program that stores the name and phone numbers. I've did a database (base.txt) and looks like this:

1µBurgerµ634-4345
2µDionµ434-4345
3µFonfonµ334-3422

The number, then when the program find the sign µ, it displays what it is after, then when it finds the other µ, it displays the phone number (the first number and the name are displayed in a combobox, the phone number in a textbox)

then the part to retreive data that doesn't work! (my friend did that I didn't had an idea how to do it)

Private Sub Form_Load()

e = 1
Open "base.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, a(e)
b = 0: c = 0: d = 0
For b = 1 To Len(a(e))
f = b
If Mid$(a(e), b, 1) = "µ" Then
If c = 1 Then d = f: Exit For
ElseIf c = 0 Then c = 1
End If
Next b
nom1.AddItem Left$(a(e), 1) & ". " & Mid$(a(e), 3, d + 3)
e = e + 1
Loop

End Sub

(nom1 = combobox)

if anyone had another way to do it, please any help would be appreciated !!!!

Thanks!
Dim3x
muTe is offline   Reply With Quote
Old 07-25-2002, 09:55 AM   #2
Professional gadfly
 
doctorgonzo's Avatar
 
Join Date: Jan 2002
Location: Minneapolis, MN
Posts: 6,364
Send a message via MSN to doctorgonzo
Instead of using the Mid$ function, use the InStr (In String) function. Because you know that each line will have two µs in there, that function would be far less messy than what you are trying to do.
doctorgonzo is offline   Reply With Quote
Old 07-25-2002, 10:33 AM   #3
Member (10 bit)
 
Join Date: Apr 2001
Location: Michigan
Posts: 850
Send a message via ICQ to HackinCowboy
InStr() will return the location of the string you're searching for. You'll still need to use Mid$ to actually retrieve the data.
HackinCowboy is offline   Reply With Quote
Old 07-25-2002, 10:47 AM   #4
Professional gadfly
 
doctorgonzo's Avatar
 
Join Date: Jan 2002
Location: Minneapolis, MN
Posts: 6,364
Send a message via MSN to doctorgonzo
Quote:
Originally posted by HackinCowboy
InStr() will return the location of the string you're searching for. You'll still need to use Mid$ to actually retrieve the data.
Yep, here's something quick-and-dirty I threw together:

Public Sub Form_Load()
Dim e As Integer, a As Integer, b As Integer, sa(255) As String

Open "base.txt" For Input As #1
e = 0
Do While Not EOF(1)
Line Input #1, sa(e)
a = InStr(sa(e), "µ") 'Find first µ
b = InStr(a + 1, sa(e), "µ") 'Find second µ
nom1.AddItem Left$(sa(e), a - 1) & ". " & Mid$(sa(e), a + 1, b - a - 1) & ": " & Mid$(sa(e), b + 1)
e = e + 1
Loop
Close #1
End Sub
doctorgonzo is offline   Reply With Quote
Old 07-25-2002, 10:52 AM   #5
Member (10 bit)
 
Join Date: Apr 2001
Location: Michigan
Posts: 850
Send a message via ICQ to HackinCowboy
Nice use of descriptive variables
Also, be sure not to have more than 255 lines in your file or you'll get an error.
HackinCowboy is offline   Reply With Quote
Old 07-25-2002, 10:54 AM   #6
Professional gadfly
 
doctorgonzo's Avatar
 
Join Date: Jan 2002
Location: Minneapolis, MN
Posts: 6,364
Send a message via MSN to doctorgonzo
Quote:
Originally posted by HackinCowboy
Nice use of descriptive variables
Also, be sure not to have more than 255 lines in your file or you'll get an error.
Like I said, it was "quick and dirty"

If I were doing this for real, I would have use real variable names, and probably sized the array to the file length. But this works for three entries.
doctorgonzo is offline   Reply With Quote
Old 07-25-2002, 12:05 PM   #7
Member (9 bit)
 
muTe's Avatar
 
Join Date: Jan 2002
Location: Quebec, Canada
Posts: 426
ok now it retreives the number and the name. but when I click on the name it doesn't show the phone number in the textbox (numero1)

Public Sub Form_Load()
Open "base.txt" For Input As #1
e = 0
Do While Not EOF(1)
Line Input #1, sa(e)
a = InStr(sa(e), "µ") 'Find first µ
b = InStr(a + 1, sa(e), "µ") 'Find second µ
nom1.AddItem Left$(sa(e), a - 1) & ". " & Mid$(sa(e), a + 1, b - a - 1)
e = e + 1
Loop
Close #1
End Sub

that's the part the program is loading the data.

and I've put something if the user change the name in the combobox, it change it to the default thing. but if he puts a number, the program crashes because of the select case...

Private Sub nom1_Change()
Select Case Left$(nom1.Text, 1)
Case 1, 2, 3, 4, 5, 6, 7, 8, 9
a = InStr(nom1.Text, ".")
c = Left$(nom1.Text, a - 1)
f = InStr(sa(c), "µ")
f = InStr(f + 1, sa(c), "µ")
numero1.Text = Mid$(sa(c), f + 1)
Case Else
nom1.Text = "Choisissez un nom"
End Select
End Sub

this is also supposed to change the textbox when the user selects a name but it doesn't.

Thanks
Dim3x
muTe is offline   Reply With Quote
Old 07-25-2002, 01:29 PM   #8
Member (10 bit)
 
Join Date: Apr 2001
Location: Michigan
Posts: 850
Send a message via ICQ to HackinCowboy
I'm a little confused about you're problems, but I think I get what you're saying.

1.) Why don't you change the Style of the combo box to 'Dropdown List' that way the user can't change the values in the combo box.

2.) You're using the change() event, switch that to the click() event. The change() event is if the values in the combo box changes.
Hope this is what you were asking.
HackinCowboy is offline   Reply With Quote
Old 07-25-2002, 02:15 PM   #9
Member (9 bit)
 
muTe's Avatar
 
Join Date: Jan 2002
Location: Quebec, Canada
Posts: 426
ok I'll try that thanks
muTe is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 12:20 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2