File Name and Combo Box issues

KoW
05-07-2003, 04:57 PM
I'm quite a bit of a n00b and I need help with some stuff for class.

I've been working on a sig generator (it's pointless and stupid, but it does what I need for the final) but I'm having a few issues.

1. I need to save each sig as a new file. As it is, I'm trying to save each sig as a file with the format "server_servername.txt" so people can go in, grab the sig for, say, International RO Chaos Server from the filr iro_chaos.txt and slap it on to a website. Here's what I have:

Open ("C:\RO Sig Machine\" & strServer & "_" & strVersion & ".dat") For Input As #1

So yeah, that doesn't work. Is there any way to use variables in a filename?

2. How in God's name do I revert a combo box to it's default setting? I'm trying to get a combo box to flip back to the first item in the list, but I just can't figure it out.

3. How can I check if a file exists already? It's the same situation as 1; I'd like to have it append if the file doesn't exist and overwrite with input if it does. I know how to set it up in a For loop, but how can I check if the file exists yet?

I know it's a lot, but if anyone could help with anything, I'd appreciate it.

Thanks in advance.

Edit: As if life wasn't complicated enough... Is there an easy way to compare three variables (technically an array) and decide which was the greatest? I just don't want to use a billion for loops.

SenorPr0n
05-07-2003, 05:17 PM
As for your first question, try setting up a variable with the filename, and then open the 'variable':

thefile = "@#$$$%" & var1 & " * " & var2
Open thefile For Input As #1
bla
bla
bla
Close #1

To check if a file exists, try opening that file in the code, and use error trapping:

OnError(whatever the code is for file not found) Do Something

Lar_19
05-07-2003, 05:40 PM
#2 The list index for first item in a combo box is zero, so to revert it...
Combo1.ListIndex = 0

#3 Use the Dir$() function to see if a file exists.

KoW
05-07-2003, 05:58 PM
Thanks for the help on those two, Lar.

Now I'm having this issue:

strFilename = cmbServer.Text & "_" & cmbVersion.Text & ".txt"
Open (strFilename) For Append As #1
strStorage = txtResult.Text
Input #1, strStorage
Close #1

I get the error "Bad File Mode" on the fourth line. What's wrong with it? txtResult.Text is multiple lines; could that be it? How do I solve that issue?

Also, Senor's solution isn't working. The file that's created is still "_.txt"

Lar_19
05-07-2003, 06:29 PM
Try it like this...Private Sub Command1_Click()
Dim ff As Integer, strFilename As String

' Get an available file number.
ff = FreeFile

' Be sure the filename variable includes the correct path.
strFilename = App.Path
strFilename = strFilename & cmbServer.Text & "_" & cmbVersion.Text & ".txt"

Open (strFilename) For Append As #ff
' Change this to Print instead of Input.
Print #ff, txtResult.Text
Close #ff

End Sub

KoW
05-07-2003, 06:35 PM
The second I saw "Print #ff" I knew what I did wrong. I solved the dillema my own way, but thanks for the help, Lar! My program is almost complete, I just need to decide on a way to set a default value.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum