Option Explicit
Public profilepath As String
Public finalprofile As String
Private Sub Form_Load()
Dim prof As String
txt_profilepath.Enabled = False
file1.Enabled = False
txt_plprofile.Text = frm_loadfile.var1
prof = frm_field.GetString(txt_plprofile.Text, "-", "C")
txt_plprofile.Text = prof + ".plp"
'txt_plprofile.Text = prof + ".plp"
End Sub
Private Sub cmd_cancel_Click()
MsgBox "Cancelled"
Unload Me
End Sub
Private Sub cmd_ok_Click()
Dim prof As String
Select Case Me.Caption
Case "Save Profile"
txt_profilepath.Text = file1.Path & "\" & file1.FileName & txt_plprofile.Text
If isFile(txt_profilepath.Text) Then
txt_plprofile.Text = frm_loadfile.var1
prof = frm_field.GetString(txt_plprofile.Text, "-", "C")
If MsgBox("File " & txt_profilepath & " exists. Do you want to overwrite the current profile?{Y/N]", vbQuestion + vbYesNo, App.ProductName + " Prompt") = vbYes Then
SaveProfile txt_profilepath.Text, pl1
finalprofile = txt_plprofile.Text
Else
txt_profilepath.Text = file1.Path & file1.FileName & "\" & prof & Format(Now, "mmddyyyyhhmmss") & ".plp"
SaveProfile txt_profilepath.Text, pl1
finalprofile = txt_plprofile.Text
End If
Else
MsgBox "Saving " & txt_profilepath & " as new profile."
SaveProfile txt_profilepath.Text, pl1
finalprofile = txt_plprofile.Text
End If
profilepath = txt_profilepath.Text
frm_field.cmd_next.Enabled = True
Case "Load Profile"
txt_profilepath.Text = file1.Path & "\" & file1.FileName
MsgBox "Loading " & txt_profilepath & " profile."
LoadProfile txt_profilepath.Text, pl1
profilepath = txt_profilepath.Text
frm_field.cmd_next.Enabled = True
End Select
Me.Hide
End Sub
Private Sub LoadProfile(WhatFile As String, TheProfile As partslist)
Dim FreeFileHandle As Integer, a$, B() As String
FreeFileHandle = FreeFile
Open WhatFile For Input As FreeFileHandle
With TheProfile
Line Input #FreeFileHandle, a ' "[Symbol] " & .symbol
B = Split(a, " ")
.symbol = B(1)
frm_field.txt_sym.Text = .symbolic
Line Input #FreeFileHandle, a ' "[Name] " & .Name
B = Split(a, " ")
.name = B(1)
frm_field.txt_name.Text = .name
Line Input #FreeFileHandle, a ' "[Quantity] " & .quantity
B = Split(a, " ")
.quantity = B(1)
frm_field.txt_qty.Text = .quantity
End With
Close FreeFileHandle
End Sub
Private Sub SaveProfile(WhatFile As String, TheProfile As namelist)
Dim FreeFileHandle As Integer
FreeFileHandle = FreeFile
Open WhatFile For Output As FreeFileHandle
With TheProfile
Print #FreeFileHandle, "[Name] " & .name
Print #FreeFileHandle, "[Quantity] " & .quantity
Print #FreeFileHandle, "[Symbolic] " & .symbol
End With
Close FreeFileHandle
End Sub
Private Sub dir1_Change()
file1.Path = dir1.Path
End Sub
Private Sub drive1_Change()
dir1.Path = drive1.Drive
End Sub
Private Sub file1_PathChange()
Me.Caption = "Dialog Box - [" & file1.Path & "]"
End Sub
Private Sub file1_Click()
txt_plprofile.Text = file1.FileName 'file1 is a file list box
End Sub
Function isFile(ByVal sFileName As String) As Integer
On Error Resume Next
Dim lFileLength As Long
Const ATTR_NORMAL = 0
isFile = False
If Dir$(sFileName, ATTR_NORMAL) <> "" Then
lFileLength = FileLen(sFileName)
If (lFileLength > 0) Then isFile = True
End If
End Function