Results 1 to 7 of 7

Thread: [RESOLVED] Input function

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2016
    Posts
    51

    Resolved [RESOLVED] Input function

    How do I apply this function? (Input)
    I get the weirdest error:
    Name:  Error.jpg
Views: 207
Size:  40.1 KB
    Any questions, ask.
    When someone talks sh*t about me:


    Are you ta'king to me?..
    Are you ta'king to the special one?..
    Are you ta'king to the special one?..
    There's nobody else here,
    you must be talking to the special one!
    Are you ta'king to me?
    Are are, are you ta'king to me?


  2. #2
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: Input function

    The input function exists for those familiar with older Microsoft BASICs, in particular VB6 (1998) and earlier.
    It is helpful for porting existing code from those earlier versions of Visual Basic, also referred to as Legacy VB on a log of forums.
    If you're writing new code it is suggested to use the later .Net framework based File IO.

    To answer your question, you have to have a file that was written, or is formatted to be compatible with what Input expects.
    You have to Open a file for Input first, providing a FileNumber as a reference.
    Then you use that same FileNumber in the Read, i.e. the Input function.
    You also pass a variable of the type you want to read, say a variable that is of type Integer.
    If the file has a string that can be interpreted as an Integer at the point where you do the Input, then it will be converted to an Integer, and your variable will contain that value.

    Again, it is suggested you don't use the function unless you need to.

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2016
    Posts
    51

    Re: Input function

    So, if I have a notepad opened with some normal text on it and I want a variable to be equal that text, how do I do it? I tryed it this way:
    Code:
    Public Sub Input(FileNumber As Integer, ByRef Value As Object)
    End Sub
    Public Function LOF(FileNumber As Integer) As Long
    End Function
    
    <variable> = Input(<number of the file>, LOF(<number of the file>))
    EDIT: I think I found my error, I had Sub instead of Function! Now I need to get back to my project to fix the rest, thanks
    Last edited by rdrmdr; Mar 1st, 2016 at 01:09 PM. Reason: I think I got it!
    When someone talks sh*t about me:


    Are you ta'king to me?..
    Are you ta'king to the special one?..
    Are you ta'king to the special one?..
    There's nobody else here,
    you must be talking to the special one!
    Are you ta'king to me?
    Are are, are you ta'king to me?


  4. #4
    PowerPoster SJWhiteley's Avatar
    Join Date
    Feb 2009
    Location
    South of the Mason-Dixon Line
    Posts
    2,256

    Re: Input function

    The specific error means there isn't an overload signature that matches the data types that you are passing to the method.

    You need to call the method with the correct data types that match one of the overloads; FileNumber needs to be an integer, and Value needs to be one of the types listed.

    But, as passel said, you should probably use the improved methods made available by the .NET framework for file I/O.
    "Ok, my response to that is pending a Google search" - Bucky Katt.
    "There are two types of people in the world: Those who can extrapolate from incomplete data sets." - Unk.
    "Before you can 'think outside the box' you need to understand where the box is."

  5. #5
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: Input function

    Simple example. It is suggested to use FreeFile to get a free file number to use, but the numbers only have to be unique to your application, so if you can keep track of what number you've used and you're not writing code to be reused, you can just pick a number (like 1 as I did here), since you can only hurt yourself if you reuse the same number in your code to try to open another file while you haven't closed the previous one.
    Code:
    Public Class Form1
    
      Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim a, b, c As Integer
        a = 1 : b = 2 : c = 3
        FileSystem.FileOpen(1, "oldVB6FileIO.tst", OpenMode.Output)
        FileSystem.Write(1, a, b, c)
        FileSystem.FileClose(1)
      End Sub
    
      Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
        Dim x, y, z As Integer
        FileSystem.FileOpen(1, "oldVB6FileIO.tst", OpenMode.Input)
        FileSystem.Input(1, x)
        FileSystem.Input(1, y)
        FileSystem.Input(1, z)
        FileSystem.FileClose(1)
        MessageBox.Show(String.Format("x={0}, y={1}, z={2}", x, y, z))
      End Sub
    End Class

  6. #6
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: Input function

    I didn't see post #3 until after I posted the above.
    If you add another button to that example, one convenient way to read the lines of a file (e.g. a file that you might open in notepad), is to use the ReadAllLines method. The method will take care of the opening and closing of the file, and all the lines will be read into an array of strings so you can access each line by accessing the array.
    This is one of the new .Net ways of doing things we were talking about.

    So, this code will read the lines of the file created by pressing button 1 in the previous example. In this case, there is only one line in the file, containing "1,2,3".
    Code:
      Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
        Dim s() As String = IO.File.ReadAllLines("oldVB6FileIO.tst")
        MessageBox.Show(s(0))
      End Sub

  7. #7

    Thread Starter
    Member
    Join Date
    Jan 2016
    Posts
    51

    Re: Input function

    Cool, thanks for letting me know about it
    When someone talks sh*t about me:


    Are you ta'king to me?..
    Are you ta'king to the special one?..
    Are you ta'king to the special one?..
    There's nobody else here,
    you must be talking to the special one!
    Are you ta'king to me?
    Are are, are you ta'king to me?


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width