Results 1 to 20 of 20

Thread: Code not reading entries !

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2018
    Location
    Athens
    Posts
    133

    Code not reading entries !

    l save some entries with the following code
    ......................................
    Dim i
    Dim a1, b1, c1 As String

    Open "c:\xxxx\Entries.Dat" For Append As #2
    For i = 1 To ItemCount
    Write #2, a1(i), b1(i), c1(i)
    Next i
    Close #2
    ..................................................
    l check the entries.Dat in the xxxx folder and the entries are there


    however when l want the entries to be written in the LV with the foll code they are NOT
    it should be noted that if the entries.Dat is in the App.Path , the reading code works fine and the entries are presented in the LV
    ..........................................
    Dim a1, b1, c1 As String
    Dim itm as ListItem

    Open "c:\xxxx\Entries.Dat" For Append As #2

    Do Until EOF(2)
    Input #2, a1, b1, c1
    Set itm = LV1.ListItems.Add(, , a1)
    itm.SubItems(1) = b1
    .....................................

    Loop

    Close #2
    ..................................
    any ideas please ..

  2. #2
    Addicted Member
    Join Date
    Nov 2011
    Posts
    233

    Re: Code not reading entries !

    Quote Originally Posted by vbgeobas View Post
    l save some entries with the following code
    ......................................
    Dim i
    Dim a1, b1, c1 As String

    Open "c:\xxxx\Entries.Dat" For Append As #2
    For i = 1 To ItemCount
    Write #2, a1(i), b1(i), c1(i)
    Next i
    Close #2
    ..................................................
    l check the entries.Dat in the xxxx folder and the entries are there


    however when l want the entries to be written in the LV with the foll code they are NOT
    it should be noted that if the entries.Dat is in the App.Path , the reading code works fine and the entries are presented in the LV
    ..........................................
    Dim a1, b1, c1 As String
    Dim itm as ListItem

    Open "c:\xxxx\Entries.Dat" For Append As #2

    Do Until EOF(2)
    Input #2, a1, b1, c1
    Set itm = LV1.ListItems.Add(, , a1)
    itm.SubItems(1) = b1
    .....................................

    Loop

    Close #2
    ..................................
    any ideas please ..
    i dont think this line is correct

    'Open "c:\xxxx\Entries.Dat" For Append As #2'

    should that not be Read, your trying to append in the second bit of code.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2018
    Location
    Athens
    Posts
    133

    Re: Code not reading entries !

    It works with
    Open "c:\xxxx\Entries.Dat" For input As #2'
    Sorry it was a copy/paste mistake

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Posts
    22,955

    Re: Code not reading entries !

    Did you really mean to define your a1 and b2 As Variant as you have?

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Oct 2018
    Location
    Athens
    Posts
    133

    Re: Code not reading entries !

    @dilettante ,
    l am not an expert developer . All l do is projects with simple VB6 code . As long as it works , it's fine with me .
    In my particular project my entries a1,b1...... h1 , some are strings , some are decimals . How else could l define them .
    l've read yours and Elroy's posts regarding variants , and l must admit , it's all Greek to me .

  6. #6
    PowerPoster
    Join Date
    Feb 2006
    Posts
    22,955

    Re: Code not reading entries !

    Maybe go to this link:

    https://docs.microsoft.com/en-us/off...iant-data-type

    Then scroll to the bottom and change the language to Greek?

  7. #7
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    8,073

    Re: Code not reading entries !

    It works with
    Does that mean your original question has been solved? Or, are you still not able to do what you desired?
    Sam I am (as well as Confused at times).

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Oct 2018
    Location
    Athens
    Posts
    133

    Re: Code not reading entries !

    @ dilettante
    Thank you for your interest . Maybe my stating "it's all Greek to me" , was rather exaggerated . What l wanted to say is that
    all this theory of Variants is beyond my knowledge of VB6 . Like l said my coding is rather 'primitive' but l manage to do what
    l want . Besides , when l get stuck , l can post my problem here in vbforum and there are guys like youself who will guide me .
    l went to the link you suggested (there is no Greek translation) , read it and got te general idea .
    Thank you again

    @SamOscarBrown . Yes thank you .

  9. #9
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    13,820

    Re: Code not reading entries !

    When you define a variable in VB 6 you must include the As keyword to define a type

    Code:
    Dim a,b,c as string
    defines c as string but a and b have no type defined and default to variants.
    Code:
    Dim a as string,b as string, c as string
    properly defines all three as a string

  10. #10
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    8,073

    Re: Code not reading entries !

    or...
    Dim a As String
    Dim b As String
    Dim c As String

    ...that is MY normal way of declaring variables (except I'd use a more descriptive term other than a, b or c)...It just makes my code easier to read (for ME, that is).
    Sam I am (as well as Confused at times).

  11. #11
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    13,820

    Re: Code not reading entries !

    Yeah same here most of the time it is one dim per line, but sometimes I will put them together on the same line to save space on the screen.

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

    Re: Code not reading entries !

    Of course, you could go old school and default some variables to non variant types.

    Code:
     DefStr S
    
    Private Sub Form_Load()
      Dim sa, sb, sc 
    
      sa = "All untyped variables starting with the letter S default to Strings, not Variants"
    
    End Sub
    "Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930

  13. #13
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    8,073

    Re: Code not reading entries !

    Oh wow...never knew THAT one...I had to look at MSDN a bit closer to see what you did...pretty cool.

    ' Variable names beginning with A through K default to Integer.
    DefInt A-K' Variable names beginning with L through Z default to String.
    DefStr L-Z

    CalcVar = 4 ' Initialize Integer.
    StringVar = "Hello there" ' Initialize String.
    AnyVar = "Hello" ' Causes "Type mismatch" error.
    Dim Calc As Double ' Explicitly set the type to Double.
    Calc = 2.3455 ' Assign a Double.

    ' Deftype statements also apply to function procedures.
    CalcNum = ATestFunction(4) ' Call user-defined function.
    ' ATestFunction function procedure definition.
    Function ATestFunction(INumber)
    ATestFunction = INumber * 2 ' Return value is an integer. End Function
    Sam I am (as well as Confused at times).

  14. #14
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    4,765

    Re: Code not reading entries !

    Hmmm, I don't think it's cool.
    I really prefer declaring my variables in a Dim statement, makes much more obvious what is going on.

  15. #15
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    33,522

    Re: Code not reading entries !

    It's a carryover from the BASIC (or maybe BASICA) days... It's some truly Old School BASIC language construct.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  16. #16
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    13,820

    Re: Code not reading entries !

    Yeah been around forever it seems. I remember using at times back in the 80s when I first started. I think it was supported in Basic, BasicA and GW Basic and may have been in Commodore Basic as well.

  17. #17
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    6,661

    Re: Code not reading entries !

    Quote Originally Posted by techgnome View Post
    It's a carryover from the BASIC (or maybe BASICA) days... It's some truly Old School BASIC language construct.

    -tg
    That is actually from QuickBasic. I don't recall that existing before that in GW-Basic or BASICA. I'm not 100% sure though. I simply don't recall it being used pre-QuickBasic.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

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

    Re: Code not reading entries !

    No, it was in the earlier versions of Microsoft Basic, across many of the various computers, i.e. Atari, Commodore, etc...
    I'm not sure just when it was introduced.
    Microsoft Basic was based on the BASIC that Bill Gates and Paul Allen were familiar with from the PDP-11 computer they had at their high school and the programing they did as teens for the local DEC company.

    The DEFINT, SNG, etc... didn't exist in DEC's BASICPlus as far as I know though.
    But it was in GWBASIC and BASICA
    From the GWBASIC manual
    DEFINT/SNG/DBL/STR Statements
    Purpose:

    To declare variable types as integer, single-precision, double-precision, or string.
    Syntax:

    DEFtype letters

    Comments:

    type is INT (integer), SNG (single-precision number), DBL (double-precision number), or STR (string of 0-255 characters).

    letters are letters (separated by commas) or range of letters of the alphabet.

    A DEFtype statement declares that variable names beginning with the letter(s) specify that type of variable. However, a type declaration character (%,!,#,$) always takes precedence over a DEFtype statement in the typing of a variable.

    If no type declaration statements are encountered, BASIC assumes all variables are single-precision. Single-precision is the default value.
    Examples:

    10 DEFDBL L-P

    All variables beginning with the letters L, M, N, O, and P will be double-precision variables.

    10 DEFSTR A
    20 A="120#"

    All variables beginning with the letter A will be string variables. The $ declaration is unnecessary in this example.

    10 DEFINT I-N, W-Z
    20 W$="120#"

    All variables beginning with the letters I, J, K, L, M, N, W, X, Y, Z will be integer variables. W$ in Line 20 establishes a string variable beginning with the letter W. However, the variable W will remain an integer elsewhere in the program.
    "Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930

  19. #19
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    13,820

    Re: Code not reading entries !

    Yep, I definitely remember using it long before I ever saw Quick Basic.

  20. #20
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    6,661

    Re: Code not reading entries !

    Ah ok. I stand corrected. I used BASICA and GW-Basic but I never used or came across Def Type statements until well after when I started using QuickBasic which came along later. I had no idea they existed prior to QuickBasic.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

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