-
Sep 12th, 2021, 03:49 AM
#1
Thread Starter
Addicted Member
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 ..
-
Sep 12th, 2021, 04:05 AM
#2
Hyperactive Member
Re: Code not reading entries !
Originally Posted by vbgeobas
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.
-
Sep 12th, 2021, 05:11 AM
#3
Thread Starter
Addicted Member
Re: Code not reading entries !
It works with
Open "c:\xxxx\Entries.Dat" For input As #2'
Sorry it was a copy/paste mistake
-
Sep 12th, 2021, 08:39 AM
#4
Re: Code not reading entries !
Did you really mean to define your a1 and b2 As Variant as you have?
-
Sep 12th, 2021, 09:43 AM
#5
Thread Starter
Addicted Member
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 .
-
Sep 12th, 2021, 02:53 PM
#6
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?
-
Sep 13th, 2021, 06:34 AM
#7
Re: Code not reading entries !
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).
-
Sep 14th, 2021, 04:48 AM
#8
Thread Starter
Addicted Member
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 .
-
Sep 14th, 2021, 08:21 AM
#9
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
-
Sep 14th, 2021, 12:51 PM
#10
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).
-
Sep 14th, 2021, 12:58 PM
#11
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.
-
Sep 15th, 2021, 06:32 AM
#12
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
-
Sep 15th, 2021, 06:36 AM
#13
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).
-
Sep 15th, 2021, 07:22 AM
#14
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.
-
Sep 15th, 2021, 08:19 AM
#15
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
-
Sep 15th, 2021, 08:57 AM
#16
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.
-
Sep 15th, 2021, 09:49 AM
#17
Re: Code not reading entries !
Originally Posted by techgnome
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.
-
Sep 15th, 2021, 10:00 AM
#18
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
-
Sep 15th, 2021, 10:09 AM
#19
Re: Code not reading entries !
Yep, I definitely remember using it long before I ever saw Quick Basic.
-
Sep 15th, 2021, 11:34 AM
#20
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|