Ctype Casting To Decimal Returning Negative Value?
Dec 2, 2011I am wondering if this is a bug. Can't understand why would CType work this way...!
View 1 RepliesI am wondering if this is a bug. Can't understand why would CType work this way...!
View 1 RepliesI am calling the function below from an Excel spreadsheet and the conversion from hex to decimal using the VAL function in the "manufacturer" variable below is coming back with a negative value. The VBA edition is 6.5.
Public Function decMEID(ByVal sKey As String) As String
Dim manufacturer As String
Dim serial As String
[code].....
[Code]...
What happens when a user wants to alocate "" as Item(DurationColumn) to integer? I get an exception. clean solution to avoid this and set 0 for ""?
Ever since I moved from VB6 to VB.NET somewhere in 2005, I've been using CType to do casting from one data type to another. I do this because it is simply faster to type, used to exist in VB6 and I do not know why I have to be using DirectCast if there is apparently no difference between them.I use TryCast once in a while because I understand that sometimes casting can fail. I however cannot get the difference between CType and DirectCast.
View 3 RepliesWhat is the cleanest, most readable way to String.Format a decimal with the following criteria
start with a sign symbol (+ or -)
a fixed number of fraction digits
no decimal separator
right aligned
pre-padded with "0"'s
I have an ASP.NET web application (VB.NET) using an Oracle database. On an insert, I need to get the identity of the inserted row back. I am trying to use RETURNING, but I keep getting a value of 1 returned.
Dim strInsert As String = "INSERT INTO L.TRANSACTIONS (LOCATION_KEY, TRANS_CREATOR, TRANS_EMAIL, TRANS_PHONE) VALUES (:location_key, :trans_creator, :trans_email, :trans_phone) RETURNING TRANS_ID INTO :ukey"
[Code].....
how do you convert a decimal ( decimal place holder = dot) to a decimal (decimal place holder =comma)?
View 6 RepliesMy brain may just be fried since it's the end of the semester, but my teacher kicked this back to fix and resubmit...she said that I am "returning the name of your function rather than your variable name".
Here is my code for all 3 forms.
code:
These are forms to calculate the cost of getting a cell phone package.
OdbcDataReader in showing decimal fields Decimal separator disappear with DB2 dsn
View 3 RepliesAfter converting all degrees-->decimal, and decimal-->hours, how can i use Tan, Cos and Sin formula in vb.net? I want the user must enter an input (which it is a coordinat-->i already convert the degrees-->decimal value as suggested by stanav and paul.
The questions like this (i only calculate on paper but dont know how to implement in code):
Input user need to enter:
-latitude local (e.g. 1.4875)
-longitude local (e.g. 103.3883333)
[CODE]...
My user requests to change the . on the numpad to a when entering text in a multiline textbox.So I was thinking about the KeyDown event.To determine if the numpad . was pressed I can do something like this [code]But now how do I change the returned charachter as a , ? All e.Key... properties are ReadOnly. The KeyPress events let me change this by providing e.KeyChar, but in that event I can't check for the numpad .
View 2 RepliesHow would I go about rounding up decimal numbers to the nearest 2 decimal places? For example $7.0000032 would be $7.01 In theory, VB would make it $7.00 but if it is > $7.00, I want it to reflect that to the nearest penny... so $3.0000001 would be $3.01
View 5 Replieshave a look at this code Dim colors() As KnownColor = CType(System.Enum.GetValues(GetType(KnownColor)), KnownColor()) Since CType is a function that returns DataType ,But here as in the code it seems that CType() is returning array having values that is assigned to color() array. How this is happening?
View 3 RepliesI have a number of different object types that I would like to pass into a function. All my objects are created from classes with a .Description property. Is it possible to determine the type of object for use as the 2nd parameter in a CType call at runtime? e.g. Debug.Print CType(MyObject, TypeOf(MyObject)).Description (I have Option Strict On) I get errors when I do this.
View 4 RepliesIn vb.net, I got an Enum defined As Integer:
Enum enUtilityTypeDetailStudentEntryWorkflow As Integer
enUTDSEW_Default = 379
[code].....
This works but it adds a lot of noise to the code and it seems like the Enum is already defined as an Integer, making me think, why do I have to assign it again?
If I have the code:Dim x as Decimal = 100.0m
Is it casting from a double to a decimal implicitly. How would I do this explicitly in vb.net?
1) One Decimal Varibale stores a decimal value
2) The value must be converted in string ( some time the comma is used as decimalplaceholder some time the dot)
3) the user modifies the value
4) i need to riconvert the string back in decimal
how can i do this
so:
Variable 123.34D ----> textBox 123,34 or 123.34 -----> variable 123.34D
I cant understand why this does not work! Hope for your intelligent answers ;)
With
CType(Controls(PicsGame(GameCount)),
PictureBox)
BorderStyle =
BorderStyle.None
Is it possible to change a datarowview object to an integer?
View 3 Repliesdim testpanel as new panel
dim test as CType(testpanel, Control))
msgbox(typename(test)) ' it gives me "panel"
'i dun get it, how can typename of test give me Panel when i explicitly call it to be converted to a Control type?
I am an experienced C/C++/C# programmer who has just gotten into VB.NET. I generally use CType (and CInt, CBool, CStr) for casts because it is less characters and was the first way of casting which I was exposed to, but I am aware of DirectCast and TryCast as well. Simply, are there any differences (effect of cast, performance, etc.) between DirectCast and CType? I understand the idea of TryCast.
View 2 RepliesI turned option strict on, wich gave me some errors. The errors are quite easy to fix, but it seems like there are several ways of doing things. [code] 'previoustime' is declared as a TimeSpan, and the column "sluttid" is defined as a TimeSpan-column.Now, as far as I know, there are two ways of solving this; using CType and using DirectCast, like this: [code]
View 4 RepliesAssume that I have this declaration (according to MSDN):
Private Declare Function PostMessage Lib "user32" ( _
ByVal hWnd As IntPtr, _
ByVal wMsg As UInteger, _
[code]....
And this is how I use it:
PostMessage(hWnd, 516, CType(2, UIntPtr), CType(0, UIntPtr))
Option Strict is turned On. So the questions are:
1. Do I need to use UIntPtr in declaration or it will be better to use UInteger?
2. Do I need to use CType function in these cases or there is a better way for this or I need to avoid declaring pointers?
does your IDE ever get amnesia?in the line before it is clearly defined.in the following line it is not.Maybe it's a faulty translation from Tangible Software.the C example i'm looking at:
IAnimatedMeshSceneNode* newNode = (IAnimatedMeshSceneNode*) oldNode->clone();
translated as:
Dim newNode As IAnimatedMeshSceneNode = CType(oldNode.clone(), IAnimatedMeshSceneNode)
had to make a dummy for it because i can't use arrays with CType.
The below is a snippet from VB that I am porting to a C# rewrite. My question is what is receipt_date after the assignment? Is it still an object or is it a string?
Dim receipt_date As Object
receipt_date = CType(dr.Item("RECTDT"), String)
Would this be the correct C# counterpart?
object receipt_date;
receipt_date = dr["RECTDT"].ToString();
After both of these execute would the VB version, receipt_date be equal to the C# version?
I have this class: Public Class Foo
[Code]...
In the f = "Bar" assignment I loose the previous X and Y values previously assigned. There's a way to overload the operator to assign to the "Value" member instead of creating a new Foo class? Or a way to obtain the target of the assignment to copy the values??
I am receiving the following error:
Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 21: 'Determine the maximum pictureID for this user
Line 22: Dim results As DataView = CType(maxPictureIDDataSource.Select(DataSourceSelectArguments.Empty), DataView)
Line 23: Dim pictureIDJustAdded As Integer = CType(results(0)(0), Integer)
[Code]....
i've got a problem here whereby my ctype doesn't work.firstly, to replicate my case briefly, i've created an extension of control class
[code]...
father.getheight 'compiler writes: Panel class doesn't support getheight, but I've already converted it to a Control with CType!end sub of course if i dim father as Control it works perfectly, but in my case father may be other objects as well that aren't controls so I had to dim father as a general object, is there a fix so i could properly convert father into a Control object?
I have a class that overrides Ctype operator to have conversion from and to String :
Public Class TotoToString
Property value As String
Public Sub New(ByVal V As String)
Me.value = V
End Sub
[Code] .....
I need to programmaticlly check one RadioButton1 in GroupBox1 in my Form.The name of RadioButton and his parent GroupBox is received from global variable 'names'.How to change GrpBx1 to names(0)?
VB.Net
Dim names as String() 'GrpBx1,RadioButton1
'WORKING but not exactly what I wanna while it's fixed to only one GroupBox:
CType(Me.GrpBx1.Controls(names(1)), RadioButton).Checked = True
[code]....