Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Writing in a file

Posted on 2000-04-02
5
Medium Priority
?
164 Views
Last Modified: 2010-05-02
Hi there!

I want a system that writes down 5 names and a number to a file.

Here is an example:
I type in these in a textbox: (the numbers are random, which I DON'T type myself)

Mike    (45)
John     (2)
Susan  (15)
Kim      (8)
Lisa      (293)

And when I open the file in a textbox, I want to get the following result:
(The numbers ARE visible)

Lisa     293
Mike     45
Susan    15
Kim      8
John     2

As you can see, the name that got the highest number, comes up first etc.

Thank you!
//Caminman
0
Comment
Question by:Caminman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 6

Expert Comment

by:Marine
ID: 2677677
How large should the random numbers be ?
0
 

Expert Comment

by:kplonk
ID: 2677740
dose this have to be a file or are you simply trying to put some name sin a random order,
0
 

Accepted Solution

by:
mfclaes earned 200 total points
ID: 2677805
Hi,

because I'm not sure where you get your random numbers, I added them in the first listbox

this sample needs 2 listboxes (list1, list2)and 3 commandbuttons (command1,... 3)

it may not be as you wanted, I think it has the functionality that you want

have fun



Option Explicit

Dim strFilepath As String

Private Sub Command1_Click()
    Call write_file
End Sub

Private Sub Command2_Click()
    Call reed_file
End Sub

Private Sub Command3_Click()
    Call init
End Sub

Private Sub Form_Load()

Call init

End Sub

Sub init()
    Randomize
    Dim intCounter As Integer
    Dim lngNumber(4) As Long
    For intCounter = 0 To 4
        lngNumber(intCounter) = Int((10000 * Rnd) + 1)
        DoEvents
    Next intCounter
   
    List1.Clear
    List1.AddItem "Mike" & Chr(44) & lngNumber(0)
    List1.AddItem "John" & Chr(44) & lngNumber(1)
    List1.AddItem "Susan" & Chr(44) & lngNumber(2)
    List1.AddItem "Kim" & Chr(44) & lngNumber(3)
    List1.AddItem "Lisa" & Chr(44) & lngNumber(4)

    Dim strName As String
    strName = "myfile"
    strFilepath = App.Path
   
    If Right(strFilepath, 1) <> "\" Then strFilepath = strFilepath & "\"
    strFilepath = strFilepath & strName & ".txt"
   
End Sub


Sub reed_file()
    On Error Resume Next
    Dim strUserName(4) As String
    Dim lngNumber(4) As Long
    Dim intCounter As Integer
    Dim intTimes As Integer
    Dim varBuffer(1) As Variant
   
    List2.Clear
   
    Open strFilepath For Input As #1
    Do While Not EOF(1)
    For intCounter = 0 To 4
        Input #1, strUserName(intCounter), lngNumber(intCounter)
        Next intCounter
    Loop
    Close #1
    For intTimes = 1 To 4
        For intCounter = 4 To 1 Step -1
            If CLng(lngNumber(intCounter)) < CLng(lngNumber(intCounter - 1)) Then
                varBuffer(0) = strUserName(intCounter)
                varBuffer(1) = lngNumber(intCounter)
                lngNumber(intCounter) = CLng(lngNumber(intCounter - 1))
                lngNumber(intCounter - 1) = varBuffer(1)
                strUserName(intCounter) = strUserName(intCounter - 1)
                strUserName(intCounter - 1) = varBuffer(0)
            End If
        Next intCounter
       Next intTimes
       
    For intCounter = 0 To 4
        List2.AddItem strUserName(intCounter) & Chr(9) & lngNumber(intCounter)
    Next intCounter
   
End Sub

Sub write_file()
    On Error GoTo errorhandler
    Dim strUserName(4) As String
    Dim lngNumber(4) As Long
    Dim intCounter As Integer
   
    Randomize
    For intCounter = 0 To 4
        lngNumber(intCounter) = Int((10000 * Rnd) + 1)
        DoEvents
    Next intCounter
   
    Open strFilepath For Output As #1
        For intCounter = 0 To List1.ListCount - 1
            Print #1, Trim(List1.List(intCounter))        ' ; ","; lngNumber(intCounter)
        Next intCounter
        Close #1
   
    Exit Sub
errorhandler:
    Resume Next
End Sub

0
 
LVL 1

Expert Comment

by:jonder
ID: 2677811
When you open the file to display your sorted names. Do you have to use a text box?  If so load your name, value into a ReDimensioned  array, then bubble sort. Then display your sorted selection to your textbox.
0
 
LVL 1

Author Comment

by:Caminman
ID: 2677958
Hi, and thank you for answering so quickly!

My description wasn't the best, but anyhow, the function of the codes were excellent, even if i have to modify them a bit.

Once again, Thank you! :)

I'll return if I have further problems!

//Caminman
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question