Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

i have the following code so far

VB
Option Explicit

Dim strNumber As String
Dim strLenNr As String
Dim NrOfZero As Integer
Dim Zeros As String

Private Sub Command1_Click()

strNumber = Int(Text1.Text)  'or whatever you use to put
                                        'your number into a var
strLenNr = Len(strNumber)  'length of number (nr of digits)

If strLenNr >= 5 Then
   'nr is already 5 digits or more
Else

   NrOfZero = 5 - strLenNr  'number of zero's to add
   Zeros = String$(NrOfZero, "0")   'Zeros now contains 'NrOfZero' zeros
   strNumber = Zeros & strNumber

End If

Text2.Text = strNumber

End Sub


However this doesn't seem to run it says "String is a type and cannot be used as an expression" - Please help ???

Thanks,
Tushar.
Posted
Comments
[no name] 25-Jul-12 15:38pm    
VB5? VB6?
NrOfZero = 5 - strLenNr <-- you need to make strLenNr a number because you cannot subtract a string from a number and strLenNr is defined as a string.
[no name] 25-Jul-12 15:50pm    
Probably If strLenNr >= 5 Then here too.

1 solution

Your code won't work. Len works on a string, and you're passing in the number. String$ appears to not be a method, I would guess.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900