|
I've got a bound DataGridView that performs some validation exactly as I want it to - providing I don't have the columns formatted.
A code snippet example of the validation that works when I don't format the columns is:
<br />
If CType(e.ProposedValue, Integer) <= intPreviousToValue Then<br />
e.Row.RowError = "Error message"<br />
e.Row.SetColumnError(e.Column, "Error message")<br />
End If<br />
Using the standard VB.NET 2005 Express formatting properties, the columns are formatted to be:
Column 0 - Numeric - no decimals
Column 1 - Numeric - no decimals
Column 2 - Currency - two decimals
If I take the formatting out, the grid validation works fine - if I put the formatting back in, I can't get the validation to work.
What am I breaking by putting the formatting in?
|
|
|
|
|
Anybody got any thoughts on this?
One thing I forgot to say is that if I put a msgbox in place, when the conditions are met, it show the message - its just the errorprovider notification icon that I can't get.
|
|
|
|
|
Hi all,
i have been trying to create some function that take the Decimal datatype to convert decimal to hexadecimal and the reverse.
my code at present uses the long datatype which go up to 9.2 E+18. Currently i am working with larger numbers.
This is my code:
Private Function ConvertDecimalToHexadecimal(ByVal number As Decimal)<br />
Dim converted As String<br />
Dim value As Long = Long.Parse(number)<br />
converted = value.ToString("X")<br />
Return converted<br />
End Function
Private Function ConvertHexadecimalToDecimal(ByVal number As String)<br />
<br />
Dim txt As String<br />
Dim value As Decimal<br />
Dim converted As String<br />
<br />
txt = UCase(Trim(number))<br />
If txt.StartsWith("&H") Then txt = txt.Substring(2)<br />
value = long.Parse(txt, Globalization.NumberStyles.HexNumber)<br />
converted = value.ToString()<br />
Return converted<br />
<br />
End Function
Is there some way of making this work for numbers up to the decimal datatype of 1.79 E+308
or if anyone knows of another way?
Thanks
|
|
|
|
|
Hi,
According to Microsoft's .NET documentation, you'll have to either use the Double type instead of Long or round you numbers to a more manageable size, before handling them.
On a less helpful note, you could make your function a little smaller like so:
<br />
Private Function ConvertDecimalToHexadecimal(ByVal number As Decimal) As String<br />
Return Double.Parse(number).ToString("X")<br />
End Function<br />
<br />
Private Function ConvertHexadecimalToDecimal(ByVal number As String) As String<br />
If UCase(Trim(number)).StartsWith("&H") Then number = number.Substring(2)<br />
Return Double.Parse(number, Globalization.NumberStyles.HexNumber).ToString<br />
End Function<br />
Hope it helps,
Johan
My advice is free, and you may get what you paid for.
|
|
|
|
|
I couldn't find any built in functions to do such large conversions. However, I had some code to convert Hex to Dec and vice versa. I made some modifications to ensure the conversion would work with the largest decimal number allowed. Here is the code which I believe works perfectly. If you discover a problem let me know. Hope this helps.
Public Class Form1
'Test conversion of the largest allowed decimal value
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim msg As String = "MaxDecimal: " & Decimal.MaxValue.ToString & _
vbCrLf & "MaxDecimal as Hex: " & DecToHex(Decimal.MaxValue).ToUpper & _
vbCrLf & "Hex converted back: " & HexToDec(DecToHex(Decimal.MaxValue)).ToString
MsgBox(msg)
End Sub
'---MAIN CONVERSION FUNCTIONS---
'Converts a decimal type to it's Hex value
'Does not support fractional numbers, so don't pass them :)
'Actually they just get rounded so nothing to worry about.
Private Function DecToHex(ByVal number As Decimal) As String
number = Decimal.Round(number)
Dim result As New System.Text.StringBuilder
Do While number > 0
Dim remainder As Integer = number Mod 16
number = number / 16D
number = Decimal.Truncate(number)
result.Insert(0, DecToHexChar(remainder))
Loop
Return result.ToString
End Function
'Converts a string of Hex characters to it's decimal equivalent
'Does not provide any validation. String must have nothing but
'valid Hex values. Although no errors should occur.
Private Function HexToDec(ByVal hex As String) As Decimal
Dim result As Decimal
For i As Decimal = 0 To hex.Length - 1
Dim chr As Char = hex.Chars(i)
result += (HexCharToDec(chr) * Pow(16, hex.Length - 1 - i))
Next
Return result
End Function
'---HELPER FUNCTIONS---
'Converts a Decimal value 0 to 15 to it's Hex character equivalent
'If number is anything else it returns String.Empty
Private Function DecToHexChar(ByVal number As Integer) As String
If number < 10 Then Return number
Select Case number
Case 10 : Return "A"
Case 11 : Return "B"
Case 12 : Return "C"
Case 13 : Return "D"
Case 14 : Return "E"
Case 15 : Return "F"
End Select
Return String.Empty
End Function
'Converts a Hex character to it's decimal equivalent
'Valid characters: 0-9, A-F
'Returns -1 if invalid
Private Function HexCharToDec(ByVal chr As Char) As Decimal
If Char.IsDigit(chr) Then Return Decimal.Parse(chr)
Select Case Char.ToUpper(chr)
Case "A" : Return 10D
Case "B" : Return 11D
Case "C" : Return 12D
Case "D" : Return 13D
Case "E" : Return 14D
Case "F" : Return 15D
End Select
Return -1D
End Function
'Raises a number to a given power
'Math.Pow and ^ were not options because they don't handle up to decimal
Private Function Pow(ByVal number As Decimal, ByVal exponent As Integer) As Decimal
Dim result As Decimal = 1
For i As Integer = 1 To exponent
result *= number
Next
Return result
End Function
End Class
-- modified at 22:38 Friday 9th February, 2007
|
|
|
|
|
Is there a VB.Net way to enumerate objects in a program running as a free standing exe?
RCarey
|
|
|
|
|
A program that's running, and is not your program ? No.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
My program. I want to click a debug menu item and get a list of objects that exist at that time. Ditto for threads.
RCarey
|
|
|
|
|
OK, you can do that with reflecton. You can reflect over your objects and get out variable names and values.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
I run Win XP sp2 and want to monitor a server. I have searched the web left to right, but I cannot find out how I retrive information about the chassis temperature or what workgroup a server is in.
There are plenty of examples showing how to display the computer name for example Private Declare Function GetComputerName Lib "kernel32".
I though I could use WMI to find the temperature. Does anybody have a small code sample?
To find the workgroup I read something about netapi32. But it seems very complex. Surely there must be an easy way to check the name of the net workgroup a computer is in.
As you can understand, I am a VBA novice .
Help greatly appreciated.
|
|
|
|
|
How to dissallow the user to open an opened form
I mean dont allow to create many instance of the same form
(if form is open dont open it again
Regards
Ramy
|
|
|
|
|
Goto the "Project->Project Properties->Application" menu in VS, and then click the "Make single instance application" check box.
Trinity: Neo... nobody has ever done this before.
Neo: That's why it's going to work.
|
|
|
|
|
i checked it
but more then one instance are still running
note i am using the following
dim fr as new form1<br />
fr.show()
do u think is there a problem with the above code?
anything should be added to it
Regards
Ramy
|
|
|
|
|
try this, but i havent test it.
dim fr as form1
if fr is nothing then
fr = new form1
end if
fr.show()
|
|
|
|
|
Creating a single instance application just prevents an application from being run more then once. It doesn't prevent a form from being created multiple times. I believe the appropriate way to create a single instance form is the following.
Public Class Form2
Private Shared m_Singleton As Form2 'Current instance
'Declared private so a new instance can't be created directly
Private Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
End Sub
'Gets the current instance of the form or passes back a new one
Shared ReadOnly Property Instance() As Form2
Get
If m_Singleton Is Nothing OrElse _
m_Singleton.IsDisposed OrElse _
m_Singleton.Disposing Then m_Singleton = New Form2
Return m_Singleton
End Get
End Property
End Class However, if this is your main form you may need to make a small tweak. The code that gets generated to load your form won't used the shared property Instance. If you get an error and can't figure it out let me know. All I did was double clicked the error and then changed the line it brought me to so that it used the Instance property.
|
|
|
|
|
thx for helping
I used your Code and
when i was calling the form with following code :
Dim frm As New frmCollectAlarms<br />
frm.Show()
I got the following error
Error 1 'AMS.frmCollectAlarms.Private Sub New()' is not accessible in this context because it is 'Private'
any hint
Regards
Ramy
|
|
|
|
|
Sorry, I should have mentioned how to use it also. The 'Sub New' was declared private so you can't create a new instance of the form. If you could create a new instance then you would be able to create multiple instances, which would defeat the purpose of a singleton form.
The proper way to access the form is through the shared property 'instance'. So to show the form you would just use
frmCollectAlarms.Instance.Show If you create a variable to point to the form you would use
dim frm as frmCollectAlarms = frmCollectAlarms.Instance However, that method isn't necessary and kind of goes around the idea of a singleton form. The reason is that you could technically have more then one frmCollectAlarms in memory, however, only one would be usefull while the others would be disposed.
One thing I learned is that the method I used isn't thread safe. I did a little research after I posted the code just to make sure I hadn't steered you wrong. If you plan on accessing the form from multiple threads then you should do a little research on creating a thread safe singleton form. However, if you don't plan on accessing it from multiple threads then I wouldn't worry about it. Although looking up singleton forms may be a good idea anyway just for future knowledge. Especially 'thread safe' singleton forms.
|
|
|
|
|
i m not using threads...
i guess its working pretty good
thx for ur help
Regards
Ramy
|
|
|
|
|
Hi all,
Im trying to close aform by pressinga button, but the form doesnt seem to close (rather it just sits in my task bar below)
i have form1 open and by pressing a button i'd like form2 to close and form3 to open so heres my code.
Form2.Close()
Dim popup As New Form3
popup.Show()
but this doesnt seem to work (the button for this code is on form1)
Thanks in Advance
Jaidev
|
|
|
|
|
It looks like you are using the form itself not an instance of the form.
i.e
Public Class Form1
Inherits System.Windows.Forms.Form
Dim f As Windows.Forms.Form
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
f = New Form2
f.Show()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
f.Close()
End Sub
End Class
|
|
|
|
|
Hello guys
an error occured while i was choosing a picture within a picture box
the error is :
item with same key has already been adding
I cant add an image to my project,not even background image for a form
I always get the above error
Note : if i open an other Project and try to add a picture,everything goes fine
Regards
Ramy
|
|
|
|
|
That's a weird designer error. Have you tried adding the image in code instead ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Coding went good
PictureBox1.Image = Image.FromFile("IMAGE_00098.jpg")
but i m still getting the same error as before ,if I m trying to add a picture not by coding
I think i have done sght in Resources things....
do u think that might cause such error?
Regards
Ramy
|
|
|
|
|
I have no idea, sorry.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
I will post this issue again...
i might get help from some1
thx
Regards
Ramy
|
|
|
|