VB6 Dim varCode As String * 2 - vb6

what does this mean?
Dim varCode As String * 2
From my basic understanding, it means string multiply 2?

That is the syntax for a fixed length string in VB6

You are declaring a string with a length of 2.
See also: String Length Declaration for Visual Basic 6.0 Users

It means that the variable has a
LIMIT on how many characters it will hold.
Important Note:
Even if the string is empty, it will represent 2 Empty Spaces.
Example, Having:
Dim MyVar * 100
would store in a Database 100 Empty spaces if you have not set it value.
It's important to know that to save Memory and DiskSpace.
Please Rate my Answer!!

Related

Change order of characters in a string in powershell

I have a thumbprint of a certificate stored in a variable and I need to change the order of its characters to write it to a registry value. If the thumbprint is like 1234567890, I need to change order of characters to 9078563412 - basically split the string to couples and write the couples in the reversed order. I don't know, how long the string will be, so I can't work with static positions of characters.
First problem is that when I tried $Thumbprint.ToString().length the result was 0, although it should've been 38. I tried to convert the Thumbprint variable to a new variable of the string type. When I used $ThumbString = $Thumbprint.ToString(), the $ThumbString variable is empty. I guess I will need to know the length for the conversion, even though I'm not sure of that. I also didn't find a way to split a string without using a delimiter.
I found a solution in one script on the net. This command does that:
$certSerialReversed = ""
-1..-38 |% {$certSerialReversed += $certSerial[2*$_] + $certSerial[2*$_ + 1]}
I found that it doesn't really matter how high the last number is (whether it is -1..-10 or -1..-50), so I just set the longest length a thumbprint can have.

Visual Basics: Assume that m is an **integer** variable that has been given a value. Write a statement that assign to the **string** variable

Visual Basics: Assume that m is an integer variable that has been given a value. Write a statement that assign to the string variable s the formatted string corresponding to the value of m with two digits to the right of the decimial point and thousands separators.
Try this
Format(CStr(m),"#,##0.00")

NumberFormatException while converting from string to integer in servlet

I know ths is a common question here. I have read the solutions and modified the code then also i am not getting the solution so I have posted my code here.
when I read a value from the text box and parse the value into int from String in servlet, why does it show NumberFormatException?
String ph=request.getParameter("phone");
int phone=Integer.parseInt(ph.trim());// exception is generated here
You can't have any characters or symbols in an int AND the maximum size of an int is 2,147,483,647 which means the phone number 555 555 5555 would be to large to store in an int.
Change the parse to a long and it should fix your problem
A good rule to follow is do not store any number like SSN or Phone numbers's in numerical primitives. You want to leave the numerical primitives for values you plan on doing something math related. Keep them as strings if at all possible.
Because the value you are feeding it is not a valid integer. Make sure it doesn't have strange characters in it.
9835008199 is higher then MAXINT, so that's probaly it.
The docs tell me:
Throws NumberFormatException - if the string does not contain a parsable integer.
On another note: do not store phone numbers as integers. You will get in trouble (you are in fact already). Rule of thumb: if you do not want to do math with a number, it's not an int, but a string.
Use isNumber function to check whether it is a valid number.

Asterisks in variable declarations in VB6

What's the meaning of the asterisk (*) and the number, after the variable declaration? As seen in WpName As String * 6
Public Type WayPoint
WpIndex As Integer
WpName As String * 6
WpLat As Double
WpLon As Double
WpLatDir As String * 1
WpLonDir As String * 1
End Type
The asterisk declares the variable as a fixed-length string, where the number indicates the length of the string:
http://www.1sayfa.com/1024/diger/vb/ch07.htm#Heading8
The declaration of a fixed-length string variable contains an asterisk (*) to tell Visual Basic that the string will be a fixed length. The final parameter, strlength, tells the program the number of characters that the variable can contain.
They may be required for an API call, see this question:
VB6 - Is there any performance benefit gained by using fixed-width strings in VB6?
The only time in VB6 or earlier that I had to use fixed length strings was with working with API calls.

What does this VB6 variable declaration do?

I just found this in some old code, and I'm not sure what it means.
Dim sTemp As String * 1
What is the * 1 at the end?
Thanks!
It means that the variable is a string of exactly one character in length.
Essentially, a fixed-length string.
It's a fixed length string of one character. This was handy cause you could define a structure of fixed strings and read a file right into the structure.
It creates a fixed-length string. In that example, the variable will only ever contain one character.

Resources