VBA Call Method based on a string value [closed] - vba

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")

Related

how do i count the replaced char in a string? [closed]

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
[so i put the string like "hello world" and want to change "l" to "a" then i need to count the no. of changed letters how do i count the change letters only? help pls[1]: https://i.stack.imgur.com/Wu1PF.jpg
a possible solution would be computing the length difference between the input string and the same one with find string substituted with "":
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
newStringTB.Text = inputTB.Text.Replace(findTB.Text, replaceTB.Text)
noOfReplacedTB.Text = Len(inputTB.Text) - Len(Replace(inputTB.Text, findTB.Text, ""))
End Sub
just change:
"Button1" to your actual command button name
"newStringTB", "findTB", "replaceTB" and "noOfReplacedTB" to your actual textboxes names

How to call a function and give it a string [closed]

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

I want to remove repeated characters in textbox [closed]

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

check a specific character in textbox visual basic? [closed]

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)

Why is the error in this VBA code? [closed]

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)