really need help

jlbryant
02-26-2003, 08:02 AM
I have a button that opens a inputbox that allows me to save some strings or settings to a text file. The following code will open the text file and input the text or settings in a combo box addnew setting at form load. Ok this is were i get messed up.
when the text is saved to the text file it looks like this
"text1"
"text2"
"text3"

Ok when the following code saves the above text to the combo addnew it looks like this
"text1"00"text2"00"text3"00 but the zeros are little sqaures.
I need it to look like this when i look at the addnew strings in the combo
text1
text2
text3 like normal ya know.


Dim ans As String
Open ("c:\windows\desktop\" & "\" & "category.txt") For Input As #1
ans = Input$(LOF(1), #1)
Close #1
cat1.AddItem ans

Flyguy
02-26-2003, 08:09 AM
You are putting the complete file in a big string.
You should either read the file line by line and add each line the the combobox or split the big string to an array and loop through all elements of the array and add the data to the combobox.

jlbryant
02-26-2003, 08:17 AM
how do you do this?

crabby
02-26-2003, 08:28 AM
Dim ans As String
Open ("c:\windows\desktop\" & "\" & "category.txt") For Input As #1
ans = Input$(LOF(1), #1)
Close #1
cat1.AddItem ans

should be changed to

Dim ans As String
Open ("c:\windows\desktop\" & "\" & "category.txt") For Input As #1
do while not eof(1)
Input #1, ans
cat1.AddItem ans
loop
Close #1

jlbryant
02-26-2003, 08:32 AM
I Did This And it works fine , is there anything wrong with it?

Dim ans As String
Open ("c:\windows\desktop\" & "\" & "category.txt") For Input As #1
Do
Input #1, ans
cat1.AddItem ans
Loop Until EOF(1) = True
Close #1

jlbryant
02-26-2003, 08:36 AM
i hate to bug ya , but now i have figured this out with everyones help!, when i write things to the txt file how do i rewrite text without writeing over existing text , what do i do if i just want to add to a text file.

Garmour
02-26-2003, 08:37 AM
Firstly, decide on a format that you want to save the information to the file.
If you want the quote marks then the method you are using is fine (ie, the write command)
If you don't want the quotes then use the print #filenumber command.
To have all your data on one line like this...
text1,text2,text3
then use something like
print #filenumber,text1.text & "," & text2.text & "," & text3.text

To read the line back in you'd need to modify your method slightly, as it will read in the entire file (including EOF chars).

You could simplify it by doing...

dim strValue1 as string, strValue2 as string, strValue3 as string
open "c:\whatever" for input as #filenumber
input #filenumber,strValue1, strValue2, strValue3
cat1.additem strValue1
cat1.additem strValue2
cat1.additem strValue3


If you actually have more than 3 values then investigate the SPLIT command and look to using an array

crabby
02-26-2003, 08:38 AM
open ("") for append as 1

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum