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 3 years ago.
Improve this question
I'm having an issue while trying to split some elements of my List Box...
So what I'm doing :
I browse for a text file that contains many Youtube links and
artist/title
All lines from this textfile are added in a Listbox (1st box left on my picture)
By clicking "Next" I want to get only the links without the artist and the titles (that are on the same lines)
Problem is I don't know how to do that...
I already saw this link and this one but can't manage to change it for my project.
I know that a YouTube link is 43 characters.
So what I'm trying to do is :
pick each line of my listbox and take only the 43 first characters (the link)
display each link on each line of my 2nd listbox.
Sorry if there are grammar mistakes, englsih isn't my native language.
Comments in-line
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'put each item in the list box into an array
Dim arrList() As String = ListBox1.Items.OfType(Of String).ToArray
'Trim each item in the array to a length of 43 characters
Dim arrURL() As String = (From url In arrList
Select url.Substring(0, 43)).ToArray
'Add the array as a Range to the items collection of the second list box
ListBox2.Items.AddRange(arrURL)
End Sub
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 3 months ago.
Improve this question
I want to find out is the task actual shown or not. (Possible it's not shown by filter, or the outline structure is collapsed)
I want to handle it in VBA.
To determine if a task is visible, all that is really needed is to use the Find method of the Application object which returns True if visible. However, the Find method moves the active cell to that task if found and selects the entire row. This is often undesirable for the end-user.
This function returns True/False depending on if the task is visible, and resets the active cell.
Function TaskIsVisible(uid As Long) As Boolean
Dim curTaskUID As Long
curTaskUID = ActiveCell.Task.UniqueID
Dim curField As String
curField = ActiveCell.FieldName
TaskIsVisible = Application.Find("Unique ID", "equals", uid)
Application.Find "Unique ID", "equals", curTaskUID
Application.SelectCellLeft
Do While ActiveCell.FieldName <> curField
SelectCellRight
Loop
End Function
Note: Any task field can be used with the Find method and the field does not have to be in the current view. Unique ID is best in this case since it's guaranteed to not match any other task.
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 2 years ago.
Improve this question
Have a listview object with some columns and some rows. The first one has an image for each line (different images). I want to save each image from each row. The filename doesn't matter (could be imgyyyyMMddHHmmss.jpg, for example). struggling to get the image. The following code does not work (the listview item cannot be converted to string).
Any clues?
Thanks
Dim tmpIndex1 As Integer
Dim tmpImage As Image
For tmpIndex = 0 To listView1.Items.Count
tmpImage = lsvAddOrderItems.Items(tmpIndex1)
tmpImage.Save()
Next
A ListView control cannot contain an Image object within one of its Items.
If you want to add images to a ListView you must associate an ImageList to the ListView control.
Then to your ImageListControl load the images with its Key
Once you have all your images inside your ImageListControl, you will fill your items with your ListViewControl with the imageKey of your ImageListControl.
Then you must change your code to:
For tmpIndex = 0 To listView1.Items.Count
tmpImage = ImageListControl.Images(lsvAddOrderItems.Items(tmpIndex1).ImageKey)
tmpImage.Save()
Next
This way the conversion will not fail.
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 have a textbox, i want the user to be able to type like a color code or something in the textbox and the form back color to change to the specific color the user typed.
Help?
If you mean that the user will be typing in something like black or blue then you need the .GetColorFromName function. The code below takes the text from TextBox1 and checks to make sure that the color is recognized. If so, the Form.BackColor is set to that colour. This way if the user mis-types a color, you wont get an error. Also, it doesn't seem to matter if you type black or Black
Dim c As Color = System.Drawing.Color.FromName(TextBox1.Text)
If c.IsKnownColor Then
Me.BackColor = c
End If
If you want to add a keyword "color" to the begining of the textbox, try this instead ..
Dim commandString As String = TextBox1.Text
If commandString.ToLower.StartsWith("color") Then
'remove the 5 letters making "color" and a space
commandString = commandString.Remove(0, 6)
Dim c As Color = System.Drawing.Color.FromName(commandString)
If c.IsKnownColor Then
Me.BackColor = c
End If
End If
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I'm new to VBA (1 month), and I can't find how to get my code to know when I select a picture in Excel.
I want to be able to autoselect the cell containing the picture if I select the picture instead of the cell.
The picture already has the same name as the cell with "INV" as start (ex: INV$A$1).
The code must also work for double clicks, as double clicking the cell triggers some subroutine.
Everything is already written, but if I click the picture rather than the cell, nothing happens.
Add a macro to your images when they're inserted. You can use the same macro for all images and check the value of Application.Caller to determine which image/shape was clicked.
Sub Pics_Clicks()
ActiveSheet.Shapes(Application.Caller).TopLeftCell.Select
End Sub
Try something like this:
Private Sub Image1_Click()
MsgBox "clicked via Click!"
End Sub
Private Sub Image1_GotFocus()
MsgBox "clicked via GotFocus!"
End Sub
Here, "Image1" is the automatically created name of a control of type Image.
Such a control is inserted to an Excel sheet in Design Mode. Double click on the control to get the event handler routine auto-edited in the VBA editor.
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
How can i grab this url and paste it in a textbox?
Logout (Kassy Daniels) · Help
from this in webbrowser1
i want it to grab the /logout.php? url cause each user is different
and just paste it in a textbox1 when you hit a button
Assuming your webbrowser is WebBrowser1,
Using WebBrowser1.Document.Links will get you a HTMLElementCollection of all of the links on the page.
You can iterate through those, and check the OuterHtml element of each of those links (which will give you a string that contains the raw link, the IDs, etc.) for the text your are looking for (in this case logout?).
Using the substring command, extract that URL, and eliminate the surrounding text, and you can plug that right into the textbox.
Update: Using Firebug or your favorite DOM tool, you can find that the logout link is in the root div of the document
Dim rootDiv As HtmlElement = WebBrowser1.Document.GetElementById("root")
Dim links As HtmlElementCollection = rootDiv.GetElementsByTagName("a")
Dim index As Integer
For i As Integer = 0 To links.Count - 1
If links(i).InnerHtml.Contains("Logout") Then
index = i
Exit For
End If
Next i
Dim stringofLink As String = links(index).OuterHtml
If the page changes in structure, this should be somewhat resilient to it, but you may need to generalize it further. Process stringofLink however you want to break it up (find the ampersand that you need and then copy from the question mark to that point).