Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am writing a program that is a multi-form inventory program for a bookstore wi

ID: 3650011 • Letter: I

Question

I am writing a program that is a multi-form inventory program for a bookstore with data saved in a textbox.

Here is what I need to do:


* Write a menu-driven multiform inventory program for a bookstore with data saved in a text file.


1. Each record of the text file should consist of 5 fields

Explanation / Answer

required code: VB Code: Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As LongDeclare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As LongDeclare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As LongDeclare Function RegEnumKeyEx Lib "advapi32.dll" Alias "RegEnumKeyExA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, lpcbName As Long, lpReserved As Long, ByVal lpClass As String, lpcbClass As Long, lpftLastWriteTime As FILETIME) As LongPublic Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long Type FILETIME dwLowDateTime As Long dwHighDateTime As LongEnd Type Public Const HKEY_CURRENT_CONFIG = &H80000005Public Const HKEY_PERFORMANCE_DATA = &H80000004Public Const KEY_ENUMERATE_SUB_KEYS = &H8Public Const HKEY_CLASSES_ROOT = &H80000000Public Const HKEY_CURRENT_USER = &H80000001Public Const HKEY_LOCAL_MACHINE = &H80000002Public Const HKEY_USERS = &H80000003Public Const HKEY_CURRENT_CONFIG = &H80000005Public Const HKEY_DYN_DATA = &H80000006Public Const REG_SZ = 1 'Unicode nul terminated stringPublic Const REG_BINARY = 3 'Free form binaryPublic Const REG_DWORD = 4 '32-bit numberPublic Const ERROR_SUCCESS = 0&Dim DispName As StringPublic Function GetSettingString(hKey As Long, _strPath As String, strValue As String, Optional _Default As String) As StringDim hCurKey As LongDim lResult As LongDim lValueType As LongDim strBuffer As StringDim lDataBufferSize As LongDim intZeroPos As IntegerDim lRegResult As Long 'Set up default valueIf Not IsEmpty(Default) ThenGetSettingString = DefaultElseGetSettingString = ""End If lRegResult = RegOpenKey(hKey, strPath, hCurKey)lRegResult = RegQueryValueEx(hCurKey, strValue, 0&, _lValueType, ByVal 0&, lDataBufferSize) If lRegResult = ERROR_SUCCESS Then If lValueType = REG_SZ Then strBuffer = String(lDataBufferSize, " ")lResult = RegQueryValueEx(hCurKey, strValue, 0&, 0&, _ByVal strBuffer, lDataBufferSize) intZeroPos = InStr(strBuffer, Chr$(0))If intZeroPos > 0 ThenGetSettingString = Left$(strBuffer, intZeroPos - 1)ElseGetSettingString = strBufferEnd If End If Else'there is a problemEnd If lRegResult = RegCloseKey(hCurKey)End FunctionSub EnumKeys()'Enumerates all software titles, then checks if they're listed in "Add/Remove Programs'Adds them to list1 and writes them to c:progs.txtDim keyname As String ' receives name of each subkeyDim keylen As Long ' length of keynameDim classname As String ' receives class of each subkeyDim classlen As Long ' length of classnameDim lastwrite As FILETIME ' receives last-write-to time, but we ignore it hereDim hKey As Long ' handle to the HKEY_LOCAL_MACHINESoftware keyDim index As Long ' counter variable for indexDim retval As Long ' function's return valueOpen "c:progs.txt" For Output As #1retval = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SoftwareMicrosoftWindowsCurrentVersionUninstall", 0, KEY_ENUMERATE_SUB_KEYS, hKey)If retval 0 ThenMsgBox "Registry key could not be opened -- aborting."Write #1, "Registry key could not be opened -- aborting."Close #1 End ' terminate the programEnd Ifindex = 0 ' initial index valueWhile retval = 0 ' while we keep having success (retval equals 0 from the above API call) keyname = Space(255): classname = Space(255) ' make room in string buffers keylen = 255 classlen = 255 ' identify the allocated space ' Get information about the next subkey, if one exists. retval = RegEnumKeyEx(hKey, index, keyname, keylen, ByVal 0, classname, classlen, lastwrite) If retval = 0 Then ' Extract the useful information from the string buffers. keyname = Left(keyname, keylen) ' trim off the excess space classname = Left(classname, classlen) ' Display the returned information. DispName = GetSettingString(HKEY_LOCAL_MACHINE, "SoftwareMicrosoftWindowsCurrentVersionUninstall" & keyname, "DisplayName") 'that checks if it is listed in "Add/Remove Programs" If DispName "" Then Form1.List1.AddItem DispName 'adds it to the list Write #1, DispName 'writes them all to a file End If End If index = index + 1 ' increment the index counterWendretval = RegCloseKey(hKey)Close #1 'closes the fileEnd Sub
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote