Discussione:
left-right e mid metodi
(troppo vecchio per rispondere)
Fabio Cirillo
2005-09-29 17:01:05 UTC
Permalink
Ragazzi in vb net,
i metodi left-right e mid per restituire un numero di caratteri di una
stringa che per esempio si trova digitata in una textbox, in vbnet è
rimasta la stessa sintassi ossia per esempio:

Microsoft.VisualBasic.Left(Me.TextBox1.Text, 2)
Microsoft.VisualBasic.Right(Me.TextBox1.Text, 2)
Mid(Me.TextBox1.Text, 3, 2)

oppure vi è una nuova procedura in net?

Ciao
Fabio
Alex
2005-09-29 17:43:44 UTC
Permalink
Una stringa altro non è che un'istanza della classe
stringa che mette a disposiozione il metodo Substring
che puo sostituirti la Mid

Mid(Me.TextBox1.Text, 3, 2) -> Me.TextBox1.Text.Substring(3,2)

per la Left e Right la cosa non è così immediata, ma il concetto è guarda
prima cosa ti offre la classe string.
--
Alex
MCP - .NET & SQL Server 2000
MBS CP - Programming & Development

UGIdotNET - http://www.ugidotnet.org
Weblog: http://blogs.ugidotnet.org/AlexBlog
Fabio Cirillo
2005-09-30 11:32:29 UTC
Permalink
Post by Alex
Una stringa altro non è che un'istanza della classe
stringa che mette a disposiozione il metodo Substring
che puo sostituirti la Mid
Mid(Me.TextBox1.Text, 3, 2) -> Me.TextBox1.Text.Substring(3,2)
per la Left e Right la cosa non è così immediata, ma il concetto è guarda
prima cosa ti offre la classe string.
Scusami alex,
ma visto che al post precedente non mi hanno ancora risposto inoltro la
domanda anche a te nel caso tu sappia darmi un'indicazione:

per abilitare il pulsante enter della tastiera all'evento key_press io
ho sempre scritto in vbnet così:

If e.KeyChar = Chr(13) Then
e.Handled = True
Me.TextBox1.Focus()
SendKeys.Send("{HOME}+{End}")
End If

è corretto oppure è una sitassi migrata dal vb6 ed in net vi è un'altra
più leggere ed efficiente? Se si mi potete fare un esempio? io sull'msdn
stavo vedendo il sintassi: System.Windows.Forms.Keys.Return ed avevo
scritto così:

If System.Windows.Forms.Keys.Return = Keys.Enter Then
e.Handled = True
Me.textbox1.Focus()
SendKeys.Send("{Home}+{End}")
End If

ma ovviamente non funziona perchè qualsiasi pulsante premo mi esegue
l'istruzione if...

ciao
fabio
Alex
2005-09-30 12:35:43 UTC
Permalink
Post by Fabio Cirillo
If e.KeyChar = Chr(13) Then
e.Handled = True
Me.TextBox1.Focus()
SendKeys.Send("{HOME}+{End}")
End If
Sul KeyPress non puoi fare diversamente come puoi vedere dal'esempio qui:
http://msdn.microsoft.com/library/ITA/cpref/html/frlrfSystemWindowsFormsKeyPressEventArgsClassKeyCharTopic.asp

' Create a TextBox control.
Dim tb As New TextBox()
AddHandler tb.KeyPress, AddressOf keypressed

Sub keypressed(ByVal o As [Object], ByVal e As KeyPressEventArgs)
' The keypressed method uses the KeyChar property to check
' whether the ENTER key is pressed.

' If the ENTER key is pressed, the Handled property is set to true,
' to indicate the event is handled.

If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Then
e.Handled = True
End If
End Sub 'keypressed
Post by Fabio Cirillo
If System.Windows.Forms.Keys.Return = Keys.Enter Then
e.Handled = True
Me.textbox1.Focus()
SendKeys.Send("{Home}+{End}")
End If
Questo tipo di controllo è posibile farlo nel KeyDown o nel KeyUp in questa
forma

If e.KeyCode = Keys.Enter Then
e.Handled = True
Me.textbox1.Focus()
SendKeys.Send("{Home}+{End}")
End If

http://msdn.microsoft.com/library/ITA/cpref/html/frlrfSystemWindowsFormsKeyEventArgsClassKeyCodeTopic.asp
--
Alex
MCP - .NET & SQL Server 2000
MBS CP - Programming & Development

UGIdotNET - http://www.ugidotnet.org
Weblog: http://blogs.ugidotnet.org/AlexBlog
Fabio Cirillo
2005-09-30 15:34:19 UTC
Permalink
Post by Alex
Post by Fabio Cirillo
If e.KeyChar = Chr(13) Then
e.Handled = True
Me.TextBox1.Focus()
SendKeys.Send("{HOME}+{End}")
End If
http://msdn.microsoft.com/library/ITA/cpref/html/frlrfSystemWindowsFormsKeyPressEventArgsClassKeyCharTopic.asp
' Create a TextBox control.
Dim tb As New TextBox()
AddHandler tb.KeyPress, AddressOf keypressed
Sub keypressed(ByVal o As [Object], ByVal e As KeyPressEventArgs)
' The keypressed method uses the KeyChar property to check
' whether the ENTER key is pressed.
' If the ENTER key is pressed, the Handled property is set to true,
' to indicate the event is handled.
If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Then
e.Handled = True
End If
End Sub 'keypressed
Post by Fabio Cirillo
If System.Windows.Forms.Keys.Return = Keys.Enter Then
e.Handled = True
Me.textbox1.Focus()
SendKeys.Send("{Home}+{End}")
End If
Questo tipo di controllo è posibile farlo nel KeyDown o nel KeyUp in questa
forma
If e.KeyCode = Keys.Enter Then
e.Handled = True
Me.textbox1.Focus()
SendKeys.Send("{Home}+{End}")
End If
http://msdn.microsoft.com/library/ITA/cpref/html/frlrfSystemWindowsFormsKeyEventArgsClassKeyCodeTopic.asp
ok grazie mille

Loading...