[Webinar] Streamline your web hosting managementRegister Today


Lots of simple code needed for a simple VB interface

Posted on 2004-10-14
Medium Priority
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:


an example of what the varibles could/would be:

FILENAME=tizzys toybox


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!

popup window that only shows if the location.ini file does not exist
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!
Question by:chinswain
  • 3
  • 2
LVL 76

Assisted Solution

by:David Lee
David Lee earned 1000 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

Author Comment

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?


Accepted Solution

Noel_Castillo earned 1000 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
      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
  ' *******
   MsgBox Error
End Function

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.


Author Comment

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?


Author Comment

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?
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.

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month11 days, 5 hours left to enroll

612 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