Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Here's Print Using Mismatch error
#1
So I was pretty sure Print Using could work with numeric variables but my code came up with a mismatch error. Upon re-reading the wiki it seems I was wrong, that Print Using works with string values. So I changed the code but have hit the same mismatch error. Here is the routine

Code: (Select All)
Dim formatString As String
formatString = "##.##"
For i = 0 To 9
    'Print Using "##.##"; i / 10; "-"; (i + 1) / 10; " |";
    Print Using formatString; i / 10; "-"; (i + 1) / 10; " |";
    For j = 1 To freq(i) / 10
        Print "*";
    Next j
    Print
Next i
I have commented out the original code of  'Print Using "##.##"; i / 10; "-"; (i + 1) / 10; " |"; which produced the error and tried to convert it all to string with that dim statement of formatString sting variable. I'm not sure what I'm missing here?
Reply
#2
Format string should BE A String ie FormatString$

oops sorry jumped the gun, missed the first line up there.

So now I think it's all the freak'n ; you used in line 5 but still checking...
b = b + ...
Reply
#3
You get a missmatch because you provide more values than you designate in the format string.
Code: (Select All)
DIM formatString AS STRING
formatString = "##.## & ##.## &" 'num;str;num;str
FOR i = 0 TO 9
    'Print Using "##.##"; i / 10; "-"; (i + 1) / 10; " |";
    PRINT USING formatString; i / 10; "-"; (i + 1) / 10; " |";
    FOR j = 1 TO freq(i) / 10
        PRINT "*";
    NEXT j
    PRINT
NEXT i
This works.

BTW you don's see the stars printet here, because the freq() array/function is not defined in this example, hence the J loop will evealuate 1 TO 0 and so never is performed.
Reply
#4
Yeah what Rho said AND what bplus said because this works too!
Code: (Select All)
Dim formatString As String
formatString = "##.##"
For i = 0 To 9
    'Print Using "##.##"; i / 10; "-"; (i + 1) / 10; " |";
    Print Using formatString; i / 10;
    Print " -";
    Print Using formatString; (i + 1) / 10;
    Print " |";
    'For j = 1 To freq(i) / 10      this doesn't do anything because freq() not declared
    '    Print "*";
    'Next j
    Print
Next i

Wait this doesn't work because i/10 never ='s or exceeds 1
Code: (Select All)
'For j = 1 To freq(i) / 10      this doesn't do anything because freq() not declared
    '    Print "*";
    'Next j
b = b + ...
Reply
#5
Code: (Select All)
For i = 0 To 9
    Print Using "##.## - ##.## |"; i / 10; (i + 1) / 10;
    For j = 1 To freq(i) / 10
        Print "*";
    Next j
    Print
Next i

is the above what you're looking for?
Reply
#6
I raise Steve a star system!
Code: (Select All)
For i = 0 To 9
    Print Using "##.## - ##.## |"; i / 10; (i + 1) / 10;
    For j = 1 To i + 1
        Print "*";
    Next j
    Print
Next i
b = b + ...
Reply
#7
Thanks very much, that was the solution Steve. I gather as Rho pointed out, my original code was forcing too many values into the print using format and the solution was to alter the print using format from "##.##", to "##.## - ##.##" as Steve suggested or "##.## & ##.## &" as RhoSigma pointed out. I haven't tried Rho's code yet but what would be the difference in the flow of data thru the two formats ( ie the diffence using a negative sign (-) v's the ampersand (&).
And thanks again
Reply
#8
The problem was basically that you weren't reserving a place for the 2nd number to go.

"##.##"  <-- this allows for one number only.

By changing the format to:
"##.## to ##.## |"
"##.## - ##.## |"
"##.## & ##.## |" <-- Edit: This actually won't work exactly the same, as explained more in the post below. Apologies.
 or just about any other layout, you're reserving space for that second number as well.

One format string per PRINT USING, with all the formatting already reserved as needed for that line.  By breaking it down into trying to make it work as multiple statements, it glitched out on you.  It's a case of just keeping it as simple as you can, BASICally.  Wink
Reply
#9
Apologies.  I didn't take a close enough look at Rho's code.

"&" is a placeholder for a string value, just as "##.##" is a placeholder for a 2-digit number with 2 decimal places.   Rho's code works a little different as his format string is set up for "#### & ####", which expects a number, followed by a string, followed by another number.   In this case, the "-" is the string he's using.  Wink

Code: (Select All)
Print Using "In the year ####, & was ## years old."; 1973, "Steve", 0

Just like the above, which is a little more obvious when tossed into a sentence like so, for us.  Wink
Reply
#10
Ah ha - Thanks again Steve. I have read the wiki a number of times... you'd think, the more I read the greater the clarity would be ... thank god for the forum 
p.s. my next reference material would have been the Bible.
Reply




Users browsing this thread: 1 Guest(s)