• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 150
  • Last Modified:

name a file from user input

in vb4 16 bit win 3.1

user types in data (8 digits long) into text1
eg text1 = cake
Using this user data (cake)  what is the code for greating this file (eg cake.dat)  , open it for output , write to it and close it.

I have tried astring = val(form1.text1.text)
                  open "c:\xxe\astring.dat" for output as #1
                       write #1: close #1
when I go to view that file it has been saved as Astring.dat
I need it saved as cake.dat
Help   ........I am SHUT OFF until I can do it!!!!!!!!
 

0
hjaycox
Asked:
hjaycox
  • 3
  • 2
1 Solution
 
mcixCommented:
Dim mstrFileName As String
Dim mlngFileHandle As Long
mstrFileName = "C:\xxe\" & Text1.Text & ".dat"
mlngFileHandle = FreeFile

Open mstrFileName For Output As #mlngFileHandle
Write #mlngFileHandle, "SOME TEST"

Close #mlngFileHandle


0
 
hjaycoxAuthor Commented:
You saved me. Thanks.......
Want 50 more points??????
answer this one.

After the "c:\xxe\" & text1.text & ".dat" has been put into the directory ,  How do I call a window that will list ALL of the .dat
files in the xxe directory.
then select one of these files and load it BACK into the original program so it can be read or modified?????
0
 
mcixCommented:
There are a couple of ways to do that...

Explain a little more about what you want to do...

Here is some generic code to fill a list box:

Function ListFiles(vstrPath As String, vstrSpec As String, lstControl As ListBox)

Dim mstrCurrentFile As String

mstrCurrentFile = Dir(vstrPath & vstrSpec)
Do While mstrCurrentFile <> ""
    lstControl.AddItem vstrPath & mstrCurrentFile
    mstrCurrentFile = Dir
Loop

End Function


Private Sub Form_Load()
    ListFiles "C:\xxe\", "*.dat", List1
End Sub

0
 
hjaycoxAuthor Commented:
This is a recipe program for the wife. She wants it simple, 3 text boxes. 1 is the name (8 bites) the second is the ingredient (800) and the last is the directions (1200). After she fills out the form she saves it by the name.dat ((((THANK YOU)))). A week later she wants to pull it up and make dinner. SO she starts the program...hits the view button.....selects the file..... loads it, reads it, maybe changes it. then if changed,  resaves it., else quits the program.

So , what do I do??? I need a window that will show all the dat files. Choose one by its name....load it to the original program etc.
0
 
mcixCommented:
hjaycox,

Start a new question on that in the Visual Basic Controls Section...

I am sure either I will have a solution for you or someone can help.

Mark
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now