Solved

Lots of simple code needed for a simple VB interface

Posted on 2004-10-14
6
220 Views
Last Modified: 2010-05-02
Hello, im new too VB and needs some babie steps with this small program i am trying to create, the purpose of it is to create an iso from a CD.
It is for use in small primary schools in england who cannot afford expensive software to do this simple task! if you could be patient with me im sure it will be fairly easy to finish!

First of all some info on this program.

It will be created in VB6.
A main window asking the teacher to insert a CD into the drive plus a box asking the user too type the name of the CD in. then click next.
the vb program will pass the name of the CD plus the location of the file server to a program called DDump (too copy the cd to iso file)
I need to call it using the command line:

ddump.exe 1:0:0 (LOCATION)(FILENAME) DONOTWAIT

an example of what the varibles could/would be:

LOCATION=\\server\store\
FILENAME=tizzys toybox

so:

ddump.exe 1:0:0 \\server\store\tizzys toybox DONOTWAIT

would be the complete command.

The location of \\server\store\ needs to be asked if location.ini does not exsist (also needs to create location.ini)
If location.ini is not there, a prompt will open asking for the location and then store this in the location.ini(after creating it!)
the program will use the location in location.ini each time it loads.

CD name needs to be asked each time the program is run and stored in the FILENAME varible (tempory varible)


The following image is of what i have created so far, the only thing missing is some simple code!
http://www.apucsd.34sp.com/storyboard.jpg


popup window that only shows if the location.ini file does not exist
http://www.apucsd.34sp.com/storyboard2.jpg
It asks for the location and stores it in the location.ini file and never appears again aslong as the .ini file exists

The vb files thus far is here: http://www.apucsd.34sp.com/Project.rar

Please note i am very new to VB but am enjoying it! this program is needed fairly quickly otherwize i would have worked on it slowly myself!

well, i hope you can help me here, many thanks!
0
Comment
Question by:chinswain
  • 3
  • 2
6 Comments
 
LVL 76

Assisted Solution

by:David Lee
David Lee earned 250 total points
ID: 12314382
Here's part of what you're looking for.  This is code you can use to launch the Ddump program.  The reason that I'm not providing more code is that I'm unclear on a couple of things.

1.  What is the format of the ini file?  Without knowing that I'm not sure how to go about writing to it.
2.  What is the ini file used for?
3.  You say that the location needs to be tested to see if the ini file exists, but the dialog-box you show in the second jpg asks for the location to create the ini file in.  How can I write code to test for a file if I don't know where to look for it at?  I have to have a location to look for the file in and if I have that, then I don't need to ask for the location to create the file.

'Include a reference in your project to: Windows Script Host Object Model
Private Sub MakeImage(strLocation As String, strFileName As String)
    Dim objShell As New WshShell, _
        strCommandLine As String
    strCommandLine = "ddump.exe 1:0:0 " & strLocation & strFileName & " DONOTWAIT"
    objShell.Exec strCommandLine
    Set objShell = Nothing
End Sub
0
 

Author Comment

by:chinswain
ID: 12314417
OK, the ini file is just a text file that contains the location of the shared folder on the "server"
when the program is first run it needs to create this file and add the shared folder location to it (in the format "\\server\images\" )
from then on the program can find the location in this file and use it, rather than prompt the user each time it loads up.
maybe there is another way of storing this information other than the ini (text) file?

0
 
LVL 3

Accepted Solution

by:
Noel_Castillo earned 250 total points
ID: 12315349

BlueDevilFan already gave the part that would let you execute your ddump.exe
Heres the code that you need to create your ini file that stores the shared folder.
I suggest that you store your ini file in ur application path. (that is App.Path).
The following codes are tested. hope this helps. :)

'Place this code on a form where you'll be needing the lcoation of shared folder
'and simply call this function.
LocOfShaFol = GetTheLocationOfSharedFolder

'Function definition
Function GetTheLocationOfSharedFolder() As String
'Heres how to read from the ini file.
SharedFolderLocation = ReadWriteINI(App.Path + "\Location.ini", "GET", "LOCATION", "SHAREDFOLDER")
If Trim(SharedFolderLocation) = "" Then
   SharedFolderLocation = InputBox("Please enter the location of the shared folder") 'This is like ur storyboard2. right?
   '......... Validate the SharedFolderLocation
   'Assuming that you already validated the path of shared folder really exist
   '..
   '..
   
   'Write the ini file
   ReadWriteINI App.Path + "\Location.ini", "WRITE", "LOCATION", "SHAREDFOLDER", SharedFolderLocation
End If

GetTheLocationOfSharedFolder = SharedFolderLocation
End Function

'Create a new module and paste the following codes

Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As Any, ByVal lpFileName As String) As Long
Declare Function WritePrivateProfileSection Lib "kernel32" Alias "WritePrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpString As String, ByVal lpFileName As String) As Long
Declare Function GetPrivateProfileSection Lib "kernel32" Alias "GetPrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long


Function ReadWriteINI(tmpFileName As String, Mode As String, tmpSecname As String, tmpKeyname As String, Optional tmpKeyValue) As String
Dim tmpString As String
Dim FileName As String
Dim secname As String
Dim keyname As String
Dim keyvalue As String
Dim anInt
Dim defaultkey As String

On Error GoTo ReadWriteINIError
'
' *** set the return value to OK
ReadWriteINI = "OK"
' *** test for good data to work with
If IsNull(Mode) Or Len(Mode) = 0 Then
  ReadWriteINI = "ERROR MODE"    ' Set the return value
  Exit Function
End If
If IsNull(tmpSecname) Or Len(tmpSecname) = 0 Then
  ReadWriteINI = "ERROR Secname" ' Set the return value
  Exit Function
End If
If IsNull(tmpKeyname) Or Len(tmpKeyname) = 0 Then
  ReadWriteINI = "ERROR Keyname" ' Set the return value
  Exit Function
End If
' *** set the ini file name
FileName = tmpFileName  ' <<<<< INI filename
'
'
' ******* WRITE MODE *************************************
  If UCase(Mode) = "WRITE" Then
      If IsNull(tmpKeyValue) Or Len(tmpKeyValue) = 0 Then
        ReadWriteINI = "ERROR KeyValue"
        Exit Function
      Else
     
      secname = tmpSecname
      keyname = tmpKeyname
      keyvalue = tmpKeyValue
      anInt = WritePrivateProfileString(secname, keyname, keyvalue, FileName)
      End If
  End If
  ' *******************************************************
  '
  ' *******  READ MODE *************************************
  If UCase(Mode) = "GET" Then
 
      secname = tmpSecname
      keyname = tmpKeyname
      defaultkey = "Failed"
      keyvalue = String$(50, 32)
      anInt = GetPrivateProfileString(secname, keyname, defaultkey, keyvalue, Len(keyvalue), FileName)
      If Left(keyvalue, 6) <> "Failed" Then        ' *** got it
         tmpString = keyvalue
         tmpString = RTrim(tmpString)
         tmpString = Left(tmpString, Len(tmpString) - 1)
      End If
      ReadWriteINI = tmpString
  End If
Exit Function
   
  ' *******
ReadWriteINIError:
   MsgBox Error
   Stop
End Function


0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:chinswain
ID: 12321999
Im having some problems assigning your code to the buttons, which code gos to which buttons and what code is for the text box?

chinswain.
0
 

Author Comment

by:chinswain
ID: 12322753





Private Sub cmdStart(strLocation As String, strFileName As String)
    Dim objShell As New WshShell, _
        strCommandLine As String
    strCommandLine = "ddump.exe 1:0:0 " & strLocation & strFileName & " DONOTWAIT"
    objShell.Exec strCommandLine
    Set objShell = Nothing
End Sub

thats my start button (starts the copy) vb is giving me a compile error:

Member already exists in a object module from which the object module derives

any ideas?
0
 
LVL 76

Expert Comment

by:David Lee
ID: 12324584
The code is correct.  I can't actually test running it with you command line since I don't have ddump.exe, but I did test it with a different command line and it worked as advertised.  I suspect that the error is a result of a duplicate name or declaration.  If this is the code that's to execute when the Start button is clicked, then I'm assuming that the Start button is named cmdStart.  If so, then this sub isn't named properly.  It should be cmdStart_Click not cmdStart.  If you'll update the file containing all the VB files with the latest changes, then I'll have a look and see if I can pinpoint the problem.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now