Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > File I/O and Registry > File Name and Combo Box issues


Reply
 
Thread Tools Display Modes
  #1  
Old 05-07-2003, 04:57 PM
KoW KoW is offline
Newcomer
 
Join Date: May 2003
Posts: 7
Default File Name and Combo Box issues


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:

Code:
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.

Last edited by KoW; 05-07-2003 at 05:24 PM.
Reply With Quote
  #2  
Old 05-07-2003, 05:17 PM
SenorPr0n's Avatar
SenorPr0n SenorPr0n is offline
Regular
 
Join Date: May 2003
Location: The vicinity of the area.
Posts: 75
Default

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
Reply With Quote
  #3  
Old 05-07-2003, 05:40 PM
Lar_19's Avatar
Lar_19 Lar_19 is offline
Senior Contributor

* Expert *
 
Join Date: May 2002
Location: Vancouver, USA
Posts: 999
Default

#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.
__________________
1011 0000 1011
Reply With Quote
  #4  
Old 05-07-2003, 05:58 PM
KoW KoW is offline
Newcomer
 
Join Date: May 2003
Posts: 7
Default

Thanks for the help on those two, Lar.

Now I'm having this issue:

Code:
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"
Reply With Quote
  #5  
Old 05-07-2003, 06:29 PM
Lar_19's Avatar
Lar_19 Lar_19 is offline
Senior Contributor

* Expert *
 
Join Date: May 2002
Location: Vancouver, USA
Posts: 999
Default

Try it like this...
Code:
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
__________________
1011 0000 1011
Reply With Quote
  #6  
Old 05-07-2003, 06:35 PM
KoW KoW is offline
Newcomer
 
Join Date: May 2003
Posts: 7
Default

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.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->