Visual Basic - Selection start / end position [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 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

Related

How do I count files in a folder based on their sizes using visual basic .net (vb.net)? [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
I want to count files in a folder based on their sizes. For example, how many files that are less than 512KB and how many files that are more than 512KB. Please help me.
Below sub-routine will help you to get the count
Sub GetFileDetails(ByVal sFolderPath As String, ByRef Filelessthan512KB As Integer, ByRef FileMorethan512KB As Integer)
Dim sFiles() As String = Directory.GetFiles(sFolderPath)
For Each file As String In sFiles
Dim oFileDetails As New FileInfo(file)
If (oFileDetails.Length / 1024) < 512 Then
Filelessthan512KB = Filelessthan512KB + 1
Else
FileMorethan512KB = FileMorethan512KB + 1
End If
Next
End Sub

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

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)

VAB Excel Form - Listbox index property given control - type mismatch [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I'm using code (from here) that loops through controls a form.
When I find a particular listbox control, I want to get the listbox index.
How do I access a listbox property given a generic control?
Something like this (untested):
Dim lb as MSForms.ListBox
Dim ctrl as MSForms.Control
For each ctrl in UserForm.Controls
If TypeName(ctrl) = "ListBox" Then
Set lb = ctrl
'Voila! Now you have a variable "lb" which represents the generic listbox control
MsgBox lb.Name & " listIndex = " & lb.ListIndex 'etc.
End If
Next

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)