|
i want user to enter only 0 to F in a textbox..
if the user enter except 0 to F, it will replace by 0..
that is what i have programmed..
but i got a problem where after the replacemnt with 0, the cursor indicator is go the starting, supppose the cursor indicator ddnt go anywhere unless the the user clicks at another option.
can u help me plss!!..thanks..
beginner VB user.
learning is lifetime.
|
|
|
|
|
Hi,
when will you start searching for the things you need, rather than just ask here?
one possible way uses keywords: KeyEventArgs, SuppressKeyPress
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
hii..
how to make a new line in an enable mulitipleline textbox?..txx
|
|
|
|
|
you may use Environment.NewLine or vbCrLf to separate the text or you may pass an string array to Lines property.
Calin
|
|
|
|
|
thanks!!..
|
|
|
|
|
Hi,
I am experiencing a strange proplem which is a property doesn't return a value when I try to use the class explicitly as shown below. I have checked to make sure if property has a value inside a class and the anawer was yes. However when try to use MetaData class inside the form Artist name returns nothing. Where do I make mistake?
Any Idea?
<br />
'FORM<br />
<br />
MetaDataFactory.GetMetaData ("FileNameGoesHere")<br />
<br />
Dim XData as New MetaData<br />
<br />
Artist = XData.Artist 'Doesn't return the value.<br />
<br />
'----------------------------------------------------------<br />
'SUB CLASS USES AN INTERFACE<br />
<Serializable()> _<br />
Public Class MetaData<br />
Implements IMetaData<br />
<br />
Private _Artist as String = Nothing<br />
<br />
Public Property Artist() As String Implements IMetaData.Artist<br />
Get<br />
Return _Artist<br />
End Get<br />
Set(ByVal value As String)<br />
_Artist = value<br />
End Set<br />
End Property<br />
<br />
Public Interface IMetaData<br />
Property Artist() As String<br />
End interface<br />
<br />
'-----------------------------------------------------------------------------<br />
'METADATAFACTORY CLASS<br />
Public Class MetaDataFactory<br />
Public Shared Function GetMetaData(ByVal filename As String) As MetaData<br />
Dim XX as new MetaData<br />
xx.Artist = "BOB MARLEY"<br />
End Function <br />
End Class<br />
<br />
<br />
<br />
What a curious mind needs to discover knowledge is noting else than a pin-hole.
modified on Sunday, February 15, 2009 11:30 AM
|
|
|
|
|
Why would it have a value when the GetMetaData() function is not called by this code:
Dim XData as New MetaData
Artist = XData.Artist 'Doesn't return the value.
Another thing is that GetMetaData needs to return xx i.e. a MetaData object.
Regards
David R
|
|
|
|
|
Sorry I forgot to type it. Just assume that it is there. It is still not functioning.
What a curious mind needs to discover knowledge is noting else than a pin-hole.
|
|
|
|
|
Try this where the changes are in bold:
Dim XData as New MetaData
XData = MetaDataFactory.GetMetaData ("FileNameGoesHere")
Artist = XData.Artist 'Doesn't return the value.
....
Public Class MetaDataFactory
Public Shared Function GetMetaData(ByVal filename As String) As MetaData
Dim XX as new MetaData
xx.Artist = "BOB MARLEY"
GetMetaData = xx
End Function
End Class
Regards
David R
|
|
|
|
|
JUNEYT wrote: Sorry I forgot to type it. Just assume that it is there. It is still not functioning.
Paste the actual code that you are using. It's very hard to find the error in the code that you are using by looking at some other code that you are not using...
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
In the GetMetaData method you create an instance of the MetaData class, put some data in it and throw away the instance.
Then you create a new instance of the MetaData class, and you expect it to contain the data that was in the instance that you threw away.
Do you see the problem?
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hi,
I have passed several types of variables as (Byte,String,int32 and etc.) into a function. The my aim is to get the value of passed variable and check to see if it is null or not. If it is null, The function should return "Undefined" as a string. If it is not, it should assign the variable's original value to function.
I have no idea how to run the function for several types of variable and get their value and assign it to the function. The vb.net is no longer supporting variants.
Thanks.
What a curious mind needs to discover knowledge is noting else than a pin-hole.
|
|
|
|
|
I'm assuming that there is only one function with one parameter.
Make the function's parameter an object. Then in the function use a series of if statements with typeof...is operator.
The function would have to return an object since you don't know whether it is a string or other type.
It's not pure OO but would do the job. Some sample of your code would help to get a better answer.
Regards
David R
|
|
|
|
|
Public Function ToStringStuff(ByVal someNumber As Nullable(Of Integer))
If (someNumber.HasValue) Then
Return someNumber.ToString()
Else
Return "Undefined"
End If
End Function
Public Function ToStringStuff(ByVal someBool As Nullable(Of Boolean))
If (someBool.HasValue) Then
Return someBool.ToString()
Else
Return "Undefined"
End If
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim a As Nullable(Of Integer) = Nothing
TextBox1.Text = ToStringStuff(a)
End Sub
Something like this?
I are troll
|
|
|
|
|
Better answer than my off-the-top-of-the-head reply.
Regards
David R
|
|
|
|
|
Thank you so much! Fantastic sample.
What a curious mind needs to discover knowledge is noting else than a pin-hole.
|
|
|
|
|
You're welcome
I are troll
|
|
|
|
|
Hey,
I have some problems with the KeyDown event. When a user keeps a key pressed, the KeyDown event keeps being fired. I don't want this to happen, I just want to trap it once so I know that the key is pressed. I use the KeyUp event to check if the key is released.
Can somebody help me out on this one?
Zaegra
Motivation is the key to software development.
|
|
|
|
|
Could you add a boolean flag and set it to true in key down and to false in key up. If the flag is true, ignore the event. Something like this in keydown:
if (keydown = false) then
keydown = true
... your other code ...
end if
and in keyup
keydown = false
|
|
|
|
|
You can't stop the event being fired.
What you could do is declare a boolean variable, e.g. keyIsDown, and set it to true in the KeyDown handler and false in the KeyUp handler. The variable would then be used to control whatever you're doing in the handlers.
Without knowing exactly what you are rying to do I can't suggest anything else.
Regards
David R
|
|
|
|
|
Well, I'd like to trap Key Combinations like Alt+F4 etcetera but I can't find a way to do this, because the event keeps being fired, so I get 20x Shift and 1x F4 Any suggestions on how to trap Key Combinations?
Motivation is the key to software development.
|
|
|
|
|
I'm a bit hazy on this since I've not used Key events for some years.
But here's my suggestion.
When KeyDown fires store the key code in a variable (as well as setting keyIsDown flag).
When the event fires again, if the current key code is same as previous just ignore it. When the code changes do whatever you have to.
One thing that stopped me using key events is that generally I wouldn't want to change the behavior of standard key combinations like Alt=F4.
Regards
David R
|
|
|
|
|
Are you checking them both at the same time, or one after another? The event gets fired alot, but firing an event doesn't eat away too much CPU-time. If you only need the combination of the keys, then try this;
Private Sub TextBox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
If (e.KeyCode = Keys.F4 And e.Shift) Then
MessageBox.Show("Hit it, Sam!")
End If
End Sub
I are troll
|
|
|
|
|
Hi,
don't try anything that adds state variables (such as a KeyIsDown variable) since that is bound to fail under special circumstances (e.g. when the app looses focus in between a key going down and up again, the state variable will be incorrect on the next KeyDown, which then won't get processed since KeyIsDown is still true...)
You don't need to track the modifier keys (ALT, CTRL, SHIFT) at all, the system does that for you: you can get their immediate value at all times; in particular there is Control.ModifierKeys which always reflects the current situation; but there is even better: each KeyDown event has a KeyEventArgs which holds properties Alt, Control, Shift.
So simply check the key is F4 and Alt is true.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
I have this code written in VFP, I converted to VB.net and it seem it is working
If any one has any comment on the code about what should I use or not use or he have better idea, please say so
' This program capture CTRL+SHIFT, it can be changed to capture any combination
' Add Timer ,Command button to the form
' In the declaration
Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Integer)
Declare Function GetKeyState Lib "user32" Alias "GetKeyState" (ByVal nVirtKey As Long) As Integer
Const VK_SHIFT = &H10
Const VK_CONTROL = &H11
'Button1_Click
Me.Timer1.Interval = 1
Me.Timer1.Enabled = True
' After clicking, try to press CTRL+SHIFT or SHIFT+CTRL
' Timer1_Tick
Dim nKeySHIFT, nKeyCTRL
nKeySHIFT = GetKeyState(VK_SHIFT)
nKeyCTRL = GetKeyState(VK_CONTROL)
If nKeySHIFT <> 0 And nKeySHIFT <> 1 And nKeyCTRL <> 0 And nKeyCTRL <> 1 Then
MessageBox.Show("SHIFT + CTRL is pressed")
Timer1.Enabled = False
End If
Samir R. Ibrahim
|
|
|
|