I'm back:

Is there any place I could send what I have as a project to be looked at for help?

Signed

The Pest

I'm trying to copy/rename a file using conditionals and a string variable

Thanks for your help

Jeff

Recommended Answers

All 27 Replies

You can copy and paste the appropriate code snippet here, just click the 'Code' button, paste it in, and the code comes out nicely indented the same as Visual Studio. Add an explanation of what the code is not doing right, any error messages, and the relevant line throwing the error.

a filename is just a string. you can combine strings using the '&' operator. If you need to add a number from an Integer variable you can use the .ToString method.

thanks for the fast reply - the machine I'm on doesnt let me open the vbp file - will post the code 2 morrow. What I'm doing is something basic but I'm taking a path name in the filecopy method and trying to use a string variable in a textbox to give me a part of the new filename. Been playing around with the & operator but I still get type mismatch and or syntax errors

Jeff

You can post your project in zip with clicking Files in this editor.
Feel free to post. We'll trying to help you.

If you are using a full path and not just the filename you will have to parse the string. One way is with the Split method

Dim filepath As String = "C:\Test.txt"
Dim FileParts() As String
'This breaks the string into 2 parts, "C:\Test.txt", and "txt".
FileParts = Split(filepath, ".")
'This puts the parts back together with an extra '1' in the filename.  filepath will be "C:\Test1.txt"
filepath = FileParts(0) & "1" & "." & FileParts(1)

You are assuming that the filename contains only one ".". That is often not the case.

Bold Text Here

Will send the code in a zip form thanks again to all that repiled.

here it is
it's a mess and I see now that it's the way I'm handling variables:

Can someone school me on how to send a file? I see the file tab and can select the zip file but it doesn't send...

Click on Files and you should see the Upload Attachments panel appear below the edit window. Click on Browse then select a file to upload. Note, there is a maximum size of one meg so if your zip file is larger than that, try deleting any exe files in the project folder and rezip.

Well lightning has struck and I was able to get my prog to generate the file (in the filecopy method). What if I wanted to include another path in the path of the filename to be be created? I got a form that the user can select an option button to select a dir;

so in other words Filecopy C:"\ whatever","c:\directories and subdirs\" how do I link them?

thanks again to all that helped me ; it took all your input and some real common sense

the directory can be returned by the DirListBox in its Path property. The Path property changes whenever the user double-clicks a folder. Handling the DirListBox Change event, will allow you to put the current path in a label, then use a button to confirm that's the path the user wants. Just remember to add a "\" before the filename.

I'm getting warmer to what I need to do ; In fact I got a DirList box and DrvList box on the form already and they are functional

here is what I have ; I apologize for the very clumsy coding (hey it sort of works tho :))

did my zip file get to you guys?

I don't see any attachments on any of your posts

will try again to get it in zip form to you

thanks again for the help

here is the files (s)

here are the files

Again I apologize for the clumsy coding - all I want to do is incorporate the drv, file and dir list boxes into the filecopy code. Dont worry about the other stuff on the form

again thanks so much for the help

Your zip file came through but none of the files with your code are in there. It's hard to know how to incorporate what you want without seeing the reast of your code.

here it is again ; I dont think I'm sending you a blank file :(

Same thing just the project header and none of the forms. How are you making the .zip file? I would suggest using 7 zip it's free and easy to use. Also I would suggest adding the whole project folder to the archive, as opposed to selecting individual files, as that is sure to get everything needed on which to base the help you'll receive.

You still do the same thing.
You do not include the form file.

Will do and again I am sorry to keep screwing this up (wait till you see my coding; haha)

Have a good day

the form is in the zip file now

You biggest problem is trying to use an ' in the folder name. since it is a restricted character I changed it to a dash. I hope you don't mind but it was very frustrating scrolling through all that unnecessary code, so I shortened it for you. Here's your adjusted code:

Dim DIRsel As String ' this is the subdirectory selected'
Dim STRfilname1 As String ' this is either lineup and sch , stats or standings
Dim STRfilname As String ' this is the team name'
Dim STRweeknm As String ' this is the number of the week desired
Dim TemplatePath As String
Dim BaseFolder As String
Private Sub Chk_wk_10_Click()
    If Chk_wk_10.Value = 1 Then
        STRweeknm = "_Wk 10"
    End If
End Sub
Private Sub Chk_wk_11_Click()
    If Chk_wk_11.Value = 1 Then
        STRweeknm = "_Wk 11"
    End If
End Sub
Private Sub chk_wk_12_Click()
    If chk_wk_12.Value = 1 Then
        STRweeknm = "_Wk 12"
    End If
End Sub
Private Sub chk_wk_13_Click()
    If chk_wk_13.Value = 1 Then
        STRweeknm = "_Wk 13"
    End If
End Sub
Private Sub chk_wk_14_Click()
    If chk_wk_14.Value = 1 Then
        STRweeknm = "_Wk 14"
    End If
End Sub
Private Sub chk_wk_15_Click()
    If chk_wk_15.Value = 1 Then
        STRweeknm = "_Wk 15"
    End If
End Sub
Private Sub chk_wk_16_Click()
    If chk_wk_16.Value = 1 Then
        STRweeknm = "_Wk 16"
    End If
End Sub
Private Sub chk_wk_17_Click()
    If chk_wk_17.Value = 1 Then
        STRweeknm = "_Wk 17"
    End If
End Sub
Private Sub chk_wk_18_Click()
    If chk_wk_18.Value = 1 Then
        STRweeknm = "_Wk 18"
    End If
End Sub
Private Sub chk_wk_19_Click()
    If chk_wk_19.Value = 1 Then
        STRweeknm = "_Wk 19"
    End If
End Sub

Private Sub Chk_wk_2_Click()
    If Chk_wk_2.Value = 1 Then
        STRweeknm = "_Wk 2"
    End If
End Sub

Private Sub chk_wk_20_Click()
    If chk_wk_20.Value = 1 Then
        STRweeknm = "_Wk 20"
    End If
End Sub

Private Sub chk_wk_21_Click()
    If chk_wk_21.Value = 1 Then
        STRweeknm = "_Wk 21"
    End If
End Sub

Private Sub chk_wk_22_Click()
    If chk_wk_22.Value = 1 Then
        STRweeknm = "_Wk 22"
    End If
End Sub

Private Sub chk_wk_23_Click()
    If chk_wk_23.Value = 1 Then
        STRweeknm = "_Wk 23"
    End If
End Sub

Private Sub chk_wk_24_Click()
    If chk_wk_24.Value = 1 Then
        STRweeknm = "_Wk 24"
    End If
End Sub

Private Sub chk_wk_25_Click()
    If chk_wk_25.Value = 1 Then
        STRweeknm = "_Wk 25"
    End If
End Sub

Private Sub chk_wk_26_Click()
    If chk_wk_26.Value = 1 Then
        STRweeknm = "_Wk 26"
    End If
End Sub

Private Sub Chk_wk_27_Click()
    If Chk_wk_27.Value = 1 Then
        STRweeknm = "_Wk 27"
    End If
End Sub

Private Sub chk_wk_28_Click()
    If chk_wk_28.Value = 1 Then
        STRweeknm = "_wk 28"
    End If
End Sub

Private Sub chk_wk_3_Click()
    If chk_wk_3.Value = 1 Then
        STRweeknm = "_Wk 3"
    End If
End Sub
Private Sub chk_wk_4_Click()
    If chk_wk_4.Value = 1 Then
        STRweeknm = "_Wk 4"
    End If
End Sub

Private Sub chk_wk_5_Click()
    If chk_wk_5.Value = 1 Then
        STRweeknm = "_Wk 5"
    End If
End Sub

Private Sub chk_wk_6_Click()
    If chk_wk_6.Value = 1 Then
        STRweeknm = "_Wk 6"
    End If
End Sub
Private Sub chk_wk_7_Click()
    If chk_wk_7.Value = 1 Then
        STRweeknm = "_Wk 7"
    End If
End Sub
Private Sub chk_wk_8_Click()
    If chk_wk_8.Value = 1 Then
        STRweeknm = "_Wk 8"
    End If
End Sub
Private Sub chk_wk_9_Click()
    If chk_wk_9.Value = 1 Then
        STRweeknm = "_Wk 9"
    End If
End Sub

Private Sub Cmd_add_all_weeks_Click()
    For Each c In Me.Controls
        If TypeOf c Is CheckBox Then
            c.Value = 1
        End If
    Next
End Sub
Private Sub cmd_exit_Click()
    End
End Sub

Private Sub Cmd_RTurbo_Click()
    For Each c In Me.Controls
        If TypeOf c Is CheckBox Then
            c.Value = 1
            FileCopy TemplatePath & "\dummy sheet.csv", BaseFolder & "\" & STRfilname1 & STRfilname & STRweeknm & ".csv"
            c.Value = 0
        End If
    Next
    DirList.Path = BaseFolder
End Sub
Private Sub cmd_run_Click()
    FileCopy TemplatePath & "\dummy sheet.csv", BaseFolder & "\" & (STRfilname1) & (STRfilname) & (STRweeknm) & ".csv"
    DirList.Path = BaseFolder
End Sub
Private Sub DirList_Change()
    ' Update the file list box to synchronize with the directory list box.
    FilList.Path = DirList.Path
    Form1.Caption = DirList.Path
End Sub
Private Sub DrvList_Change()
    On Error GoTo DriveHandler
    DirList.Path = DrvList.Drive
    Form1.Caption = FilList.Path
    Exit Sub
DriveHandler:
    DrvList.Drive = DirList.Path
    Exit Sub
End Sub
Private Sub Form_Load()
    TemplatePath = "l:\"
    BaseFolder = "l:\sports fantasy folder\MLB-13"
    For Each c In Me.Controls
        If TypeOf c Is CheckBox Then
            c.Value = 0
        ElseIf TypeOf c Is OptionButton Then
            c.Value = False
        End If
    Next
End Sub

Private Sub Opt_bhut_jolokia_Click()
    If Opt_bhut_jolokia.Value = True Then
        DIRsel = "bhut_jolokia"
    End If
End Sub

Private Sub Opt_lineup_n_sch_Click()
    If Opt_lineup_n_sch.Value = True Then
        STRfilname1 = "lineup and sch_"
    End If
End Sub

Private Sub Opt_standings_Click()
    If Opt_standings.Value = True Then
        STRfilname1 = "standings_"
    End If
End Sub

Private Sub Opt_stats_Click()
    If Opt_stats.Value = True Then
        STRfilname1 = "stats_"
    End If
End Sub
Private Sub chk_wk_1_Click()
    If chk_wk_1.Value = 1 Then
        STRweeknm = "_Wk 1"
    End If
End Sub
Private Sub txt_filename_Change()
    STRfilname = txt_filename.Text
End Sub

on a side note if you're going to use a computer that doesn't have VB6 on it, you can always load the .frm file into wordpad and copy and paste it into your message, using the Code option.

I told you it would be very clumsy ; my education VB wise comes from here and few VB4 books.

I can't tell you how much I appreciate your help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.