Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Lets say i have a textbox containing the string "hello".
Is there a way in which can i check that the 3rd character of textbox.text = "l"?
We are talking about visual basic, of course.
Thanks!
You could use this function
Private Function checkCharacter(thisString As String,
searchCharacter As Char,
index As Integer)
Try
Return thisString(index) = searchCharacter
Catch
Return False
End Try
End Function
Call it like this
Dim result As Boolean = checkCharacter(TextBox1.Text, "l"c, 2)
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
Okay, I want to call the function OpenApp() (located in a class called API.vb), but when calling it I want to pass a string to it like that:
API.OpenApp("Settings")
That's good, but how can I detect that this string has been passed, like so the function knows there's a string?
if you want to do this then you need to add a definition to the OpenApp() function so the function know what he should do with "settings" strings.
Private Sub OpenApp(dial As String)
Select Case dial
Case "settings"
MsgBox("lol")
Case "something"
MsgBox("ok")
End Select
End Sub
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am using VB.Net.
I need to remove all the repeated characters in textbox
For Example:
myy naaaame isss Johnn
to
my name is John
can anyone help me out please?
So even I, knowing zilch about VB.NET and RegEx figured it out in like 20 mins:
Sub Main()
Dim input As String = "myy naaaame isss Johnn"
' You need a regex group that matches any char: (.)
' ... and a back reference: \1
' ... and a count more than one: {1,}
Dim rgx As New Regex("(.)\1{1,}")
' use the regex to Replace by the first char of the match group
Dim output As String = rgx.Replace(input, New MatchEvaluator(Function(ByVal m)
Return m.Value.First
End Function))
End Sub
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
im currently stuck on a problem with visual basic. I need to get the start and the end of the selection, in the example on the image it should be 12/19. Couldnt find anything on the internet.. I guess im just to stupid... Hope you can help me
Not clear from the question, but it looks like a TextBox control on a UserForm. If that's the case, then you can get the start and end of the current selection using the SelStart and SelLength properties:
Dim p1 As Long
p1 = TextBox1.SelStart
Dim p2 As Long
p2 = p1 + TextBox1.SelLength
If that is a System.Windows.Controls.TextBox then you can use the selection properties:
.SelectionStart
.SelectionLength
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
If I declared an array of strings, and the strings are each a Sub name, how can I call the Sub of that name without needing an if statement?
Example pseudo code:
Set String Array = {"sub1","sub2","sub3"}
for each String str in Array
call str 'where str is a Sub
next str
I do know how to create an array and call Subs; I just don't know how to call a Sub using a string value.
Try this:
Application.Run (str)
I just learned about this by doing something similar. You can also pass a variable to that sub by doing:
Application.Run (str, "YourValue")
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
When I run this VBA code, I get an error.
Option Explicit
Sub CreateBorder()
ActiveCell.CurrentRegion.BorderAround
LineStyle:=xlDot, Weight:=xlThick, Color=RGB(255,0,0)
End Sub
The error seems to come up in the Sub CreateBorder() line. What is the problem?
There are two issues:
you can't split a statement across two lines (unless you use a _ at the end of the first line)
parameters names need to be followed by := (you use Color=...)
So it can be:
ActiveCell.CurrentRegion.BorderAround LineStyle:=xlDot, Weight:=xlThick, Color:=RGB(255, 0, 0)
or
ActiveCell.CurrentRegion.BorderAround _
LineStyle:=xlDot, Weight:=xlThick, Color:=RGB(255, 0, 0)