- My Forums
- Tiger Rant
- LSU Recruiting
- SEC Rant
- Saints Talk
- Pelicans Talk
- More Sports Board
- Fantasy Sports
- Golf Board
- Soccer Board
- O-T Lounge
- Tech Board
- Home/Garden Board
- Outdoor Board
- Health/Fitness Board
- Movie/TV Board
- Book Board
- Music Board
- Political Talk
- Money Talk
- Fark Board
- Gaming Board
- Travel Board
- Food/Drink Board
- Ticket Exchange
- TD Help Board
Customize My Forums- View All Forums
- Show Left Links
- Topic Sort Options
- Trending Topics
- Recent Topics
- Active Topics
Started By
Message
Any VB.net gurus on this board?
Posted on 2/28/17 at 10:33 am
Posted on 2/28/17 at 10:33 am
I've got a question that I hope someone can answer. Anyone up for it?
Posted on 2/28/17 at 11:01 am to finchmeister08
I know a thing or two. Whatcha got?
Posted on 2/28/17 at 1:14 pm to JollyGreenGiant
Okay, here it goes
CheckBoxList1 (populated by a folder browser dialog)
AB01AA.dwg
BA01AA.dwg
CD01AA.dwg
EA01AA.dwg
FL01AA.dwg
CheckBoxList 2 (popluated by a separate folder browser dialog)
BASE ANGLE DETAIL BA01AA.dwg
CRANE TIE BACK DETAIL TOP RUNNING CRANE CD01AA.dwg
GUTTER CLIP EA01AA.dwg
POST HUNG EAVE FLASHING FL01AA.dwg
RIGID FRAME ANCHOR BOLT SETTING AB01AA.dwg
what i'm trying to accomplish is copy the selected/checked items from checkboxlist1 into another folder(selected from a third folder browser dialog) and rename them with the names from the checkboxlist2
i have the copy method working. i just have to include the renaming portion.
here's the code i'm using to copy...
eta: sorry for the late response. i didn't check on this thread for replies until after i got back from lunch.
CheckBoxList1 (populated by a folder browser dialog)
AB01AA.dwg
BA01AA.dwg
CD01AA.dwg
EA01AA.dwg
FL01AA.dwg
CheckBoxList 2 (popluated by a separate folder browser dialog)
BASE ANGLE DETAIL BA01AA.dwg
CRANE TIE BACK DETAIL TOP RUNNING CRANE CD01AA.dwg
GUTTER CLIP EA01AA.dwg
POST HUNG EAVE FLASHING FL01AA.dwg
RIGID FRAME ANCHOR BOLT SETTING AB01AA.dwg
what i'm trying to accomplish is copy the selected/checked items from checkboxlist1 into another folder(selected from a third folder browser dialog) and rename them with the names from the checkboxlist2
i have the copy method working. i just have to include the renaming portion.
here's the code i'm using to copy...
quote:
For Each file As IO.FileInfo In ListBox1.CheckedItems
IO.File.Copy(file.FullName, IO.Path.Combine(TextBox3.Text, file.Name))
Next
eta: sorry for the late response. i didn't check on this thread for replies until after i got back from lunch.
This post was edited on 2/28/17 at 1:15 pm
Posted on 2/28/17 at 1:32 pm to finchmeister08
Hmm...
How do you know which file name from list 1 corresponds to which file name from list 2?
Is the order guaranteed to match up?
(e.g. AB01AA.dwg -> BASE ANGLE DETAIL BA01AA.dwg)
How do you know which file name from list 1 corresponds to which file name from list 2?
Is the order guaranteed to match up?
(e.g. AB01AA.dwg -> BASE ANGLE DETAIL BA01AA.dwg)
Posted on 2/28/17 at 1:52 pm to JollyGreenGiant
quote:
How do you know which file name from list 1 corresponds to which file name from list 2?
that's what i'm trying to figure out. i don't know if the sorting of the list has anything to do with it or not. as of right now, the list just sorts in an alpha-numeric order.
what i want the program to do is change "AB01AA.dwg" to "RIGID FRAME ANCHOR BOLT SETTING AB01AA.dwg" and so on..
Posted on 2/28/17 at 2:28 pm to finchmeister08
Ohh... I didn't notice the bit on the end of the file names in list 2 match the names in list 1.
I don't think there is a one-liner to do that unles you can use linq, but this should do it.
For Each file As IO.FileInfo In ListBox1.CheckedItems
....Dim NewFileName As String = FindListBox2ItemThatContains(file.name)
....If NewFileName.Trim.Length > 0 Then _
........IO.File.Copy(file.FullName, IO.Path.Combine(TextBox3.Text, NewFileName.Trim))
Next
Function FindListBox2ItemThatContains(ByVal listBox1FileName As String) As String
....For i As Integer = 0 To ListBox2.Items.Count - 1
........If ListBox2.Items(i).Text.Trim.Contains(listBox1FileName) Then
............Return ListBox2.Items(i).Text
........End If
....Next
....Return ""
End Function
I haven't tested this or anything, but it should get you on the right track.
I don't think there is a one-liner to do that unles you can use linq, but this should do it.
For Each file As IO.FileInfo In ListBox1.CheckedItems
....Dim NewFileName As String = FindListBox2ItemThatContains(file.name)
....If NewFileName.Trim.Length > 0 Then _
........IO.File.Copy(file.FullName, IO.Path.Combine(TextBox3.Text, NewFileName.Trim))
Next
Function FindListBox2ItemThatContains(ByVal listBox1FileName As String) As String
....For i As Integer = 0 To ListBox2.Items.Count - 1
........If ListBox2.Items(i).Text.Trim.Contains(listBox1FileName) Then
............Return ListBox2.Items(i).Text
........End If
....Next
....Return ""
End Function
I haven't tested this or anything, but it should get you on the right track.
This post was edited on 2/28/17 at 2:29 pm
Posted on 2/28/17 at 3:01 pm to JollyGreenGiant
i've got it pasted and the only issues it's have thus far is the "NewFileName" after the "Dim". it's saying, "Variable 'NewFilename' hides a variable in an enclosing block."
what's that mean?
what's that mean?
Posted on 2/28/17 at 3:02 pm to finchmeister08
nevermind, i had that same variable defined elsewhere. i got it fixed. now on to testing.
Posted on 2/28/17 at 3:08 pm to finchmeister08
You can call that whatever you want if there's a conflict elsewhere.
Posted on 2/28/17 at 3:39 pm to JollyGreenGiant
this is what i got and i have no clue what it means
Posted on 2/28/17 at 4:38 pm to finchmeister08
Do you need to use .name instead of .text?
Posted on 2/28/17 at 4:51 pm to mctiger1985
holy shite, that worked. but it only did 4 of the 5 files.
what could cause that?
what could cause that?
Posted on 2/28/17 at 5:01 pm to finchmeister08
Whoops. Didn't notice you were looping over FileInfo types. Good catch, mctiger1985.
The only reason I could see it skipping a file is if there are some spaces or something that are throwing off the Contains() function.
Maybe try putting .Trim on the end of listBox1FileName and ListBox2.Items(i).Text?
Like this:
........If ListBox2.Items(i).Text.Trim.Contains(listBox1FileName.Trim) Then
............Return ListBox2.Items(i).Text.Trim
........End If
The only reason I could see it skipping a file is if there are some spaces or something that are throwing off the Contains() function.
Maybe try putting .Trim on the end of listBox1FileName and ListBox2.Items(i).Text?
Like this:
........If ListBox2.Items(i).Text.Trim.Contains(listBox1FileName.Trim) Then
............Return ListBox2.Items(i).Text.Trim
........End If
Posted on 2/28/17 at 5:09 pm to JollyGreenGiant
that didn't work either
Posted on 2/28/17 at 5:18 pm to finchmeister08
okay, i caught it
the file on the left has a .DWG extension
the file on the right has a .dwg extension
the file on the left has a .DWG extension
the file on the right has a .dwg extension
Posted on 2/28/17 at 9:41 pm to finchmeister08
It's always something stupid like that. Honestly, if case doesn't matter, I should've included a .ToUpper (or .ToLower) when trying to see if the filename contains a particular string.
Usually pretty standard, but I was going off the top of my head. So much of that stuff just becomes automatic the more you do it.
Glad you got it going.
Posted on 3/1/17 at 8:46 am to JollyGreenGiant
where does the .ToUpper/.ToLower go? i tried putting it where you suggested and i get the red squiggly lines.
Posted on 3/1/17 at 8:53 am to finchmeister08
This line:
should be
This makes the string comparisons non-case-sensitive.
quote:
........If ListBox2.Items(i).Text.Trim.Contains(listBox1FileName) Then
should be
quote:
........If ListBox2.Items(i).Text.Trim.ToUpper.Contains(listBox1FileName.ToUpper) Then
This makes the string comparisons non-case-sensitive.
Posted on 3/1/17 at 1:36 pm to JollyGreenGiant
that worked
Thanks for the help man. Just so I don't feel like you did the work for me(because you basically did), can you break down the code and walk me through what each portion does and what it means? If you have the time of course. I'm kinda learning on the fly.
Thanks for the help man. Just so I don't feel like you did the work for me(because you basically did), can you break down the code and walk me through what each portion does and what it means? If you have the time of course. I'm kinda learning on the fly.
Posted on 3/2/17 at 2:24 pm to finchmeister08
Loop over every filename that is checked in ListBox1
For Each file As IO.FileInfo In ListBox1.CheckedItems
Use the function FindListBox2ItemThatContains (see below) to find the item in ListBox2 that contains the text of the current file
....Dim NewFileName As String = FindListBox2ItemThatContains(file.name)
If there is an item in ListBox2 corresponding to the current file in ListBox1
....If NewFileName.Trim.Length > 0 Then _
Make a copy of the source filepath (file.Fullname) and save it in the new directory (TextBox3.Text) with the filename from ListBox2 (NewFileName.Trim)
........IO.File.Copy(file.FullName, IO.Path.Combine(TextBox3.Text, NewFileName.Trim))
We're done with this file in ListBox1. Move on to the next one, if there are any left
Next
This Function will search through ListBox2 and Return the Filename that contains the text in listBox1FileName
Function FindListBox2ItemThatContains(ByVal listBox1FileName As String) As String
Loop over all items in ListBox2
....For i As Integer = 0 To ListBox2.Items.Count - 1
If the current item (at index i) contains the text in listBox1FileName
........If ListBox2.Items(i).Text.Trim.Contains(listBox1FileName) Then _
We've found what we're looking for. Exit the function and return that filename
............Return ListBox2.Items(i).Text
The current item (at index i) didn't contain the text in listBox1FileName, move on to the next item in ListBox2
....Next
We've run out of items in ListBox2 to check. There aren't any that contain the text in listBox1FileName. So, we return a blank string. (Have to return something)
....Return ""
End Function
For Each file As IO.FileInfo In ListBox1.CheckedItems
Use the function FindListBox2ItemThatContains (see below) to find the item in ListBox2 that contains the text of the current file
....Dim NewFileName As String = FindListBox2ItemThatContains(file.name)
If there is an item in ListBox2 corresponding to the current file in ListBox1
....If NewFileName.Trim.Length > 0 Then _
Make a copy of the source filepath (file.Fullname) and save it in the new directory (TextBox3.Text) with the filename from ListBox2 (NewFileName.Trim)
........IO.File.Copy(file.FullName, IO.Path.Combine(TextBox3.Text, NewFileName.Trim))
We're done with this file in ListBox1. Move on to the next one, if there are any left
Next
This Function will search through ListBox2 and Return the Filename that contains the text in listBox1FileName
Function FindListBox2ItemThatContains(ByVal listBox1FileName As String) As String
Loop over all items in ListBox2
....For i As Integer = 0 To ListBox2.Items.Count - 1
If the current item (at index i) contains the text in listBox1FileName
........If ListBox2.Items(i).Text.Trim.Contains(listBox1FileName) Then _
We've found what we're looking for. Exit the function and return that filename
............Return ListBox2.Items(i).Text
The current item (at index i) didn't contain the text in listBox1FileName, move on to the next item in ListBox2
....Next
We've run out of items in ListBox2 to check. There aren't any that contain the text in listBox1FileName. So, we return a blank string. (Have to return something)
....Return ""
End Function
Popular
Back to top
Follow TigerDroppings for LSU Football News