Sub routine definition what does $ mean - vb.net

Okay I have never used vb script and I am trying to convert a legacy vb module to c#. The syntax is fine but man this function definition just complete threw me for a loop.
What does $ % and # mean in the declaration.
Like for example pop(name$,balance#, id%)

They are called Type Characters. From MSDN:
Visual Basic supplies a set of identifier type characters, which you can use in a declaration to specify the data type of a variable or constant.
Here is the list, reprinted from the link:
Identifier type character Data type Example
---------------------------------------------------------------------
% Integer Dim L%
& Long Dim M&
# Decimal Const W# = 37.5
! Single Dim Q!
# Double Dim X#
$ String Dim V$ = "Secret"

Related

"VBA.len" is 4 times slower than "len" (?!) [duplicate]

When I run the following macro:
Sub try()
Dim num As Integer
num = 123
MsgBox Len(num)
MsgBox VBA.Len(num)
End Sub
The first Msgbox displays 2 and the second Msgbox displays 3.
If I remove the first line which says Dim num As Integer, both MsgBoxes display 3.
Can anyone explain why?
Len and LenB are not just ordinary functions, they are keywords, and as such are found on the list of VBA keywords (although LenB is only mentioned after you click through to Len).
Mid would be another example of such keyword disguised as function, whereas e.g. Left isn't on the list at all, because that is just an ordinary function.
It has to be a keyword because one of its jobs is to perform the compile-time task of determining the storage size of a variable. E.g. with private user-defined types, an ordinary function could not do that at all:
Private Type foo
a As Long
b As String
End Type
Sub TestLens()
Dim f As foo
MsgBox Len(f) ' OK
MsgBox VBA.Len(f) ' Compile time error
End Sub
The fact that the object browser brings you to VBA.Len when you press Shift+F2 on that Len(f) is both correct and misleading.
The Len(f) here does not actually call the VBA.Len function that determines the string size, it simply cannot do that because it would require coercing a private struct into a Variant. Instead it calculates the size of foo at compile time and substitutes the result as a literal constant into the executable.
In your example the Len(num) calculates the compile-time size of variable num (which is 2) and substitutes the constant 2 into the resulting object code, whereas VBA.Len(num) packs the value of num into a Variant and passes that variant to VBA.Len where it's further converted to string "123" and the length of that is returned.
It has to do with the way that VB stores integers and how the Len() function handles arguments that are not strings.
When a datatype that is not a string is passed to the Len() function, it returns the nominal number of bytes used to store the data (VB uses 2 bytes to store an integer). See the documentation for the Len function.
The Len() function will automatically cast the variant variable (which is created by assigning a value to a variable without declaring it first) as a string. The return isn't changing because the storage allocation changes (although it does; variants require 16 bytes of storage space, minimum). Since the implicitly declared variable is actually a variant type, VB will automatically change its type based on the situation. In this case, Len() expects a string so VB makes the variable a string.
You could use Msgbox Len(Cstr(num)) to cast the integer variable as a string before passing it to the Len function if your intent is to return the number of characters in your integer value.

VB.Net $ in end of string

I came across the following VB.Net code:
Dim Test as String = "9999"
Dim Test2 as String = Test$
What does $ mean in a string's name, such as is used in the second line?
This is a Type Notifier, which identifies the usage of Test as a string.
See also:
http://www.aivosto.com/vbtips/stringopt.html
what is the meaning of the dollar sign after a method name in vb.net

What is this Ampersand tailed to variable name

In some tutorials I find variables used with ampersand at the end of their names like with boxType& here:
%Include "lsconst.lss"
Dim boxType As Long, answer As Integer
boxType& = MB_YESNO + MB_ICONQUESTION
answer% = MessageBox("Do you want to continue?", boxType&, _
"Continue?")
I am learning Lotus Script while developing, so I seem to have missed some basics!
I would like to know what this ampersand in this context mean.
This a a so called "type suffix" and tells you, that boxType is of Type Long and answer is of type Integer. Usually you use this instead of declaring variables explicitly. Or you use it, to "see" in the variable, what type it is. Read this link or your designer Help (Topic: About data types (LotusScript Language) ) to find out more about this.
Here are the prefixes from the linked document:
Integer = %
Long = &
Single = !
Double = #
Currency = #
String = $

What does a percentage symbol mean as part of a variable name?

I'm just looking at some VB.NET code and I came across this:
Dim var%
Later var is set to 0.
What's the purpose of the percent sign (%)?
(Google and SO search failed me)
Dim varname% is ancient BASIC syntax for "varname is an integer". This has been around for a very long time in the history of the BASIC family, and is supported in Visual Basic.NET (although I, personally, wouldn't recommend it - it can be rather opaque, as discovered by you).
It is shorthand for declaring "var" as of Type Integer, and has roots in the early, early days of BASIC (yes...old-school DOS BASIC).
So this:
Dim var%
is equivalent to:
Dim var As Integer
Here is the actual MS documentation:
https://support.microsoft.com/en-us/kb/191713
% Integer
& Long
! Single
# Double
$ String
# Currency
Putting a % sign at the end of the variable name in Visual Basic indicates that it is an integer. This was used by programmers in the old VB days, I am not sure why it is still present in VB.NET. Don't use it in new code, for all you know it might be gone in future versions of VB.NET.
& : Long
% : Integer
'# : Double
! : Single
# : Decimal
$ : String

convert string to double in vb.net

data table contain column named as Fld_primary. this column contain value like 0.00 it is double datatype in mysql table.i want store that datatable value in double variable. am always getting error when i convert to double datatype.
my code
-------
Dim ds5 As dataset1.DTSUMDataTable = TA5.GetData(users)
Dim dttot As Double
dttot = CType(ds5("fld_primary").ToString, Double)
Error
Conversion from string "fld_primary" to type 'Integer' is not valid.
Edited # 3:01 AM with most recent screen caps.
Sometimes I find myself second guessing certain code based on people's answers, but I went ahead and took the time to check if the code that they are all using is even valid:
As you can see that code is a no go, so I used the correct code you see at the bottom there to reference a column.
However, if you wish to get a single cell use the chunk of code below that uses the foreach loop (the rest is my basic setup to show you how it works):
"Y" will equal the value of the datatable cell and you may convert it using the Double.Parse() method:
Dim y = Double.Parse(zDataRow("cat").ToString())
Be careful, if you have multiple rows you will notice that the value of y will change as it makes its way through all the rows.
you can convert it using the Convert class.
Dim dttot As Double = Convert.ToDouble(ds5("fld_primary"))
Your error is actually: ds5 expects an integer as a parameter, so using ds5("fld_primary") is not valid in your code. Perhaps you can try ds5(0)("fld_primary").
After you fixed it, use
dttot = Double.Parse(whatever_string_you_should_put_here)
If you cannot ensure your string must be a valid double, then use Double.TryParse.
You are better off using the 'Double.TryParse' way of converting as this handles any errors better and simply returns a boolean if succesful or not, using 'parse' will throw an exception which isnt anywhere near as elegant.
Dim dub as Double = 0
Double.TryParse("Your String Here", dub)
Try using Double.TryParse(text,value)
Try using this:
For a=0 to yourgridview.rows.count-1
Yourgridview.rows(a).cells(targetcolumnnumber).value=cdbl(Yourgridview.rows(a).cells(targetcolumnnumber).value)
Next