Santosh 的个人资料Santosh Kumar照片日志列表更多 ![]() | 帮助 |
|
|
Add-Ins Visible only to the user who installs Visual BasicA user who has not installed Visual Basic cannot see any Add-Ins in the Add-In dialog in Visual Basic. The reason is that Visual Basic retrieves available Add-Ins based on the CurrentUser Settings in the Registry. To resolve the issue the Add-Ins need to be registered for each user. You can refer http://support.microsoft.com/?id=190212 for variously possibilities on registering add-ins. If you have installed Visual Basic / Visual Studio at its default location then you can try the following scripts. Either you copy these codes and paste into ms-dos command prompt or you can use it as a ms-dos batch file. "%systemroot%\system32\regsvr32.exe" "%programfiles%\microsoft visual studio\vb98\Wizards\PDWizard\PDADDIN.DLL" "%systemroot%\system32\regsvr32.exe" "%programfiles%\microsoft visual studio\vb98\Wizards\CTRLWIZ.DLL" "%systemroot%\system32\regsvr32.exe" "%programfiles%\microsoft visual studio\vb98\Wizards\AXDOCWIZ.DLL" "%systemroot%\system32\regsvr32.exe" "%programfiles%\microsoft visual studio\vb98\Wizards\AITOOL.DLL" "%systemroot%\system32\regsvr32.exe" "%programfiles%\microsoft visual studio\vb98\Wizards\APPWIZ.OCX" "%systemroot%\system32\regsvr32.exe" "%programfiles%\microsoft visual studio\vb98\Wizards\CLSSBLD.DLL" "%systemroot%\system32\regsvr32.exe" "%programfiles%\microsoft visual studio\vb98\Wizards\DATAFORM.OCX" "%systemroot%\system32\regsvr32.exe" "%programfiles%\microsoft visual studio\vb98\Wizards\MSDATOBJ.DLL" "%systemroot%\system32\regsvr32.exe" "%programfiles%\microsoft visual studio\vb98\Wizards\PROPPGWZ.DLL" "%systemroot%\system32\regsvr32.exe" "%programfiles%\microsoft visual studio\vb98\Wizards\RESEDIT.DLL" "%systemroot%\system32\regsvr32.exe" "%programfiles%\microsoft visual studio\vb98\Wizards\TEMPMGR.DLL" "%systemroot%\system32\regsvr32.exe" "%programfiles%\microsoft visual studio\vb98\Wizards\WIZMAN.DLL" "%systemroot%\system32\regsvr32.exe" "%programfiles%\microsoft visual studio\Common\Tools\VCM\VCMMGR.DLL" "%systemroot%\system32\regsvr32.exe" "%programfiles%\microsoft visual studio\Common\Tools\VS-Ent98\vmodeler\RVBADDIN.DLL" "%systemroot%\system32\regsvr32.exe" "%programfiles%\microsoft visual studio\Common\Tools\VS-Ent98\vmodeler\RVBADDINMENUS.DLL" "%systemroot%\system32\regsvr32.exe" "%programfiles%\microsoft visual studio\Common\Tools\VS-Ent98\vmodeler\RVBRESO.DLL" »»»»»»» by Santosh Kumar ? Original @ http://santu4you.spaces.live.com Retrieving attribute values from Microsoft WMI ClassesWMI stands Windows Management Instrumentation in Microsoft Windows operating systems. It is a set of extensions to the Windows Driver Model that provides Operating System interface to provide information and notification. The following code will retrive the values from each of the properties of Win32_BIOS class This example uses instance of Win32_BIOS class and a list of class deffers dependending upon what is installed in the system. This list commonly includes classes like Win32_1394Controller, Win32_ACE, Win32_Account, Win32_AccountSID, Win32_ApplicationService, Win32_BIOS, Win32_BaseBoard, Win32_BaseService, Win32_Battery, Win32_Binary, Win32_BindImageAction, Win32_BootConfiguration, Win32_Bus, Win32_CDROMDrive, Win32_COMApplication, Win32_COMClass, Win32_COMSetting, Win32_CacheMemory, Win32_ClassInfoAction, Win32_ClassicCOMClass, Win32_ClassicCOMClassSetting, Win32_CodecFile, Win32_CommandLineAccess, Win32_ComponentCategory, Win32_ComputerSystem, Win32_ComputerSystemProduct, Win32_Condition, Win32_CreateFolderAction, Win32_CurrentProbe, Win32_DCOMApplication, Win32_DCOMApplicationSetting, Win32_DMAChannel, Win32_Desktop, Win32_DesktopMonitor, Win32_DeviceMemoryAddress, Win32_Directory, Win32_DirectorySpecification, Win32_DiskDrive, Win32_DiskPartition, Win32_DisplayConfiguration, Win32_DisplayControllerConfiguration, Win32_DriverVXD, Win32_DuplicateFileAction, Win32_Environment, Win32_EnvironmentSpecification, Win32_ExtensionInfoAction, Win32_Fan, Win32_FileSpecification, Win32_FloppyController, Win32_FloppyDrive, Win32_FontInfoAction, Win32_Group, Win32_HeatPipe, Win32_IDEController, Win32_IRQResource, Win32_InfraredDevice, Win32_IniFileSpecification, Win32_Keyboard, Win32_LaunchCondition, Win32_LoadOrderGroup, Win32_LogicalDisk, Win32_LogicalFileSecuritySetting, Win32_LogicalMemoryConfiguration, Win32_LogicalProgramGroup, Win32_LogicalProgramGroupItem, Win32_LogicalShareSecuritySetting, Win32_MIMEInfoAction, Win32_MSIResource, Win32_MemoryArray, Win32_MemoryDevice, Win32_MethodParameterClass, Win32_MotherboardDevice, Win32_MoveFileAction, Win32_NTEventlogFile, Win32_NTLogEvent, Win32_NetworkAdapter, Win32_NetworkAdapterConfiguration, Win32_NetworkClient, Win32_NetworkConnection, Win32_NetworkLoginProfile, Win32_NetworkProtocol, Win32_ODBCAttribute, Win32_ODBCDataSourceSpecification, Win32_ODBCDriverSpecification, Win32_ODBCSourceAttribute, Win32_ODBCTranslatorSpecification, Win32_OSRecoveryConfiguration, Win32_OnBoardDevice, Win32_OperatingSystem, Win32_PCMCIAController, Win32_POTSModem, Win32_PageFile, Win32_PageFileSetting, Win32_PageFileUsage, Win32_ParallelPort, Win32_Patch, Win32_PatchPackage, Win32_PhysicalMemory, Win32_PhysicalMemoryArray, Win32_PnPEntity, Win32_PointingDevice, Win32_PortConnector, Win32_PortResource, Win32_PortableBattery, Win32_PowerManagementEvent, Win32_PrintJob, Win32_Printer, Win32_PrinterConfiguration, Win32_PrivilegesStatus, Win32_Process, Win32_ProcessStartup, Win32_Processor, Win32_Product, Win32_ProgIDSpecification, Win32_ProgramGroup, Win32_ProgramGroupOrItem, Win32_Property, Win32_PublishComponentAction, Win32_QuickFixEngineering, Win32_Refrigeration, Win32_Registry, Win32_RegistryAction, Win32_RemoveFileAction, Win32_RemoveIniAction, Win32_ReserveCost, Win32_SCSIController, Win32_SID, Win32_SMBIOSMemory, Win32_ScheduledJob, Win32_SecurityDescriptor, Win32_SecuritySetting, Win32_SelfRegModuleAction, Win32_SerialPort, Win32_SerialPortConfiguration, Win32_Service, Win32_ServiceControl, Win32_ServiceSpecification, Win32_Share, Win32_ShortcutAction, Win32_ShortcutFile, Win32_ShortcutSAP, Win32_SoftwareElement, Win32_SoftwareElementCondition, Win32_SoftwareFeature, Win32_SoftwareFeatureAction, Win32_SoundDevice, Win32_StartupCommand, Win32_SystemAccount, Win32_SystemDriver, Win32_SystemEnclosure, Win32_SystemMemoryResource, Win32_SystemSlot, Win32_TapeDrive, Win32_TemperatureProbe, Win32_Thread, Win32_TimeZone, Win32_Trustee, Win32_TypeLibraryAction, Win32_USBController, Win32_UninterruptiblePowerSupply, Win32_UserAccount, Win32_VideoConfiguration, Win32_VideoController, Win32_VoltageProbe, Win32_WMISetting. More on this... The Visual Basic Code Sub Get_Win32_Information() Dim vList, vObj On Local Error Resume Next Set vList = GetObject("winmgmts:{impersonationLevel=impersonate}").InstancesOf("Win32_BIOS") For Each vObj In vList Debug.Print "BiosCharacteristics = " & vObj.BiosCharacteristics Debug.Print "BuildNumber = " & vObj.BuildNumber Debug.Print "Caption = " & vObj.Caption Debug.Print "CodeSet = " & vObj.CodeSet Debug.Print "CurrentLanguage = " & vObj.CurrentLanguage Debug.Print "Description = " & vObj.Description Debug.Print "IdentificationCode = " & vObj.IdentificationCode Debug.Print "InstallableLanguages = " & vObj.InstallableLanguages Debug.Print "InstallDate = " & vObj.InstallDate Debug.Print "LanguageEdition = " & vObj.LanguageEdition Debug.Print "ListOfLanguages = " & vObj.ListOfLanguages Debug.Print "Manufacturer = " & vObj.Manufacturer Debug.Print "Name = " & vObj.Name Debug.Print "OtherTargetOS = " & vObj.OtherTargetOS Debug.Print "PrimaryBIOS = " & vObj.PrimaryBIOS Debug.Print "ReleaseDate = " & vObj.ReleaseDate Debug.Print "SerialNumber = " & vObj.SerialNumber Debug.Print "SMBIOSBIOSVersion = " & vObj.SMBIOSBIOSVersion Debug.Print "SMBIOSMajorVersion = " & vObj.SMBIOSMajorVersion Debug.Print "SMBIOSMinorVersion = " & vObj.SMBIOSMinorVersion Debug.Print "SMBIOSPresent = " & vObj.SMBIOSPresent Debug.Print "SoftwareElementID = " & vObj.SoftwareElementID Debug.Print "SoftwareElementState = " & vObj.SoftwareElementState Debug.Print "Status = " & vObj.Status Debug.Print "TargetOperatingSystem = " & vObj.TargetOperatingSystem Debug.Print "Version = " & vObj.Version Next End Sub The Debug.Print Output BuildNumber = Caption = BIOS Date: 06/05/02 16:58:00 Ver: 08.00.00 CodeSet = CurrentLanguage = enUS Description = BIOS Date: 06/05/02 16:58:00 Ver: 08.00.00 IdentificationCode = InstallableLanguages = 1 InstallDate = LanguageEdition = Manufacturer = Intel Corp. Name = BIOS Date: 06/05/02 16:58:00 Ver: 08.00.00 OtherTargetOS = PrimaryBIOS = True ReleaseDate = 20020605******.******+*** SerialNumber = SMBIOSBIOSVersion = LY84510A.86A.0011.P05.0206051658 SMBIOSMajorVersion = 2 SMBIOSMinorVersion = 3 SMBIOSPresent = True SoftwareElementID = BIOS Date: 06/05/02 16:58:00 Ver: 08.00.00 SoftwareElementState = 3 Status = OK TargetOperatingSystem = 0 Version = BIOS Date: 06/05/02 16:58:00 Ver: 08.00.00 »»»»»»» by Santosh Kumar ? Original @ http://santu4you.spaces.live.com Listing all Microsoft WMI Non Associated Classes with its Methods and PropertiesWMI stands Windows Management Instrumentation in Microsoft Windows operating systems. It is a set of extensions to the Windows Driver Model that provides Operating System interface to provide information and notification. The following code will list the entire non-associated class name and their method name along with property name. This code will help to find those keywords that can be used for further WNI scripting The Visual Basic Code Sub Get_Win32_Classdetail() vStrComp = "." Set vObjWmiService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & vStrComp & "\root\cimv2") For Each vObjAllClass In vObjWmiService.SubclassesOf() vIsAssociated = 0 If Left(vObjAllClass.Path_.Class, 5) = "Win32" Then For Each Qualifier In vObjAllClass.Qualifiers_ If LCase(Trim(Qualifier.Name)) = "association" Then vIsAssociated = 1 Exit For End If Next If vIsAssociated = 0 Then Debug.Print vObjAllClass.Path_.Class Set vObjCurClass = vObjWmiService.Get(vObjAllClass.Path_.Class) Debug.Print vbTab & "Properties" For Each vObjItem In vObjCurClass.properties_ Debug.Print vbTab & vbTab & vObjItem.Name Next Debug.Print vbTab & "Methods" For Each vObjItem In vObjCurClass.methods_ Debug.Print vbTab & vbTab & vObjItem.Name Next Debug.Print End If End If Next End Sub The Debug.Print Output
»»»»»»» by Santosh Kumar ? Original @ http://santu4you.spaces.live.com How to convert an Oracle BLOB column image into Long RAW using Visual BasicPrivate Sub cmdGo_Click() On Error GoTo ErrHnd Dim adCon As New ADODB.Connection Dim adStream As New ADODB.Stream Dim adRstOne As New ADODB.Recordset Dim adRstTwo As New ADODB.Recordset Dim vComp As Double Dim vDown As Double If adRstOne.State = 1 Then adRstOne.Close If adCon.State = 1 Then adCon.Close adCon.Provider = "OraOledb.oracle" adCon.Open tSrv, tUsr, tPwd adCon.CursorLocation = adUseClient adRstOne.Open "select EmpID from EmpDetail", adCon Do While Not adRstOne.EOF If adRstTwo.State = 1 Then adRstTwo.Close adRstTwo.Open "select EmpBLOB, EmpLRAW from EmpGallery" & " where EmpID=" & _ adRstOne!EmpID, adCon, adConadOpenDynamic, adLockOptimistic If Not adRstTwo.EOF Then If Not IsNull(adRstTwo!EmpBLOB) Then adRstTwo!EmpLRAW = adRstTwo!EmpBLOB adRstTwo.Update End If vDown = vDown + 1 End If vComp = vComp + 1 lSts = vDown & " updated and " & vComp & " scanned . . ." lSts.Refresh adRstOne.MoveNext Loop lSts = vDown & " updated and " & vComp & " scanned . . . Done" GoTo ExitSub ErrHnd: lSts = Err.Description ExitSub: If adRstOne.State = 1 Then adRstOne.Close If adRstTwo.State = 1 Then adRstTwo.Close If adCon.State = 1 Then adCon.Close If adStream.State = 1 Then adStream.Close End Sub How to save all Oracle BLOB images to a folder using Visual BasicPrivate Sub cmdGo_Click() On Error GoTo ErrHnd Dim adCon As New ADODB.Connection Dim adStream As New ADODB.Stream Dim adRst As New ADODB.Recordset Dim adRst As New ADODB.Recordset Dim vComp As Double Dim vDown As Double If adRst.State = 1 Then adRst.Close If adCon.State = 1 Then adCon.Close adCon.Provider = "OraOledb.oracle" adCon.Open tSrv, tUsr, tPwd adCon.CursorLocation = adUseClient adStream.Type = adTypeBinary adRst.Open "select empid, empphoto from empgallery", adCon Do While Not adRst.EOF If adStream.State = 1 Then adStream.Close adStream.Open If Not IsNull(adRst!empphoto) Then vDown = vDown + 1 adStream.Write adRst!empphoto adStream.SaveToFile App.Path & "\" & adRst!empid & ".jpg", adSaveCreateOverWrite End If vComp = vComp + 1 lSts = vDown & " downloaded and " & vComp & " scanned . . ." lSts.Refresh adRst.MoveNext Loop lSts = vDown & " downloaded and " & vComp & " scanned . . . Done" GoTo ExitSub ErrHnd: lSts = Err.Description ExitSub: If adRst.State = 1 Then adRst.Close If adRst.State = 1 Then adRst.Close If adCon.State = 1 Then adCon.Close If adStream.State = 1 Then adStream.Close End Sub Visual Basic, Serial Port / Communication Port programming with MSComm32Windows hides much of the complexity of serial communications and auto-matically puts any received characters in a receive buffer and characters sent into a transmission buffer. The receive buffer can be read by the program whenever it has time and the transmit buffer is emptied when it is free to send characters. In order to use the Comm component the files MSCOMM16.OCX (for a 16-bit module) or MSCOMM32.OCX (for a 32-bit module) must be present in the %WINDIR%\SYSTEM32 directory. The class name is MSComm. It has got the following Errors ComEventBreak: A Break was received. ComEventCDTO: CD (RLSD) Timeout. ComEventCTSTO: CTS Timeout. ComEventDSRTO: DSR Timeout. ComEventFrame: Framing Error. ComEventOverrun: Data Lost. ComEventRxOver: Receive buffer overflow. ComEventRxParity: Parity Error. ComEventTxFull: Transmit buffer full. ComEventDCB: Unexpected error retrieving DCB] And the following Events ComEvCD: Change in the CD line. ComEvCTS: Change in the CTS line. ComEvDSR: Change in the DSR line. ComEvRing: Change in the Ring Indicator. ComEvReceive: Received RThreshold # of chars. Call MyInput(MSComm1.Input) ComEvSend: There are SThreshold number of characters in the transmit buffer. ComEvEOF: An EOF character was found in the input stream. The program assumptions But the example I presenting here is entirely a different approach. It’s a completely generalized program that can be used for connecting any device, which has got comm/serial port connector. The following example assumes some symbols e.g. ‘@’,’$’, ‘#’ etc. as a control character and the external device is also programmed accordingly. Also, I am a Label and ListBox control to handle the step-by-step activities. The generalized codes '''''Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "mscomm32.ocx" '''''Str declarations Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) '''''End declarations Private Sub pc2device() On Error GoTo ErrHnd Call doOpen_CommPort Dim ff As Integer Dim curRec As String Dim totRec As Integer Dim vCtr As Integer Dim vDBase() As String Dim vExit As Long totRec = 0 lblMsgMgr = "Verifying records . . ." ff = FreeFile Open txtFile For Input As #ff Do While Not EOF(ff) Line Input #ff, curRec ReDim Preserve vDBase(totRec) vDBase(totRec) = curRec totRec = totRec + 1 Loop Close #ff lblMsgMgr = totRec & " records found" lblMsgMgr = "Sending request . . ." MSCommI.Output = "$" Do While DoEvents If MSCommI.Input = "@" Then Exit Do Loop lblMsgMgr = "Got response . . ." lblMsgMgr = "Sending data . . ." vCtr = 0 For vCtr = 0 To totRec - 1 vExit = 0 Do If MSCommI.Input = "#" Then MSCommI.OutBufferCount = 0 Exit Do End If vExit = vExit + 1: If vExit > 123456 Then _ Err.Raise 12345, "Author's message", "Device not responding . . ." Loop Call TransferThisString(vDBase(vCtr), 0) MSCommI.Output = Chr(10) lblStatus = (totRec - vCtr - 1) & " records remaining" lblStatus.Refresh Next vCtr lblMsgMgr = "Data transfered successfuly . . ." Call doShut_CommPort Exit Sub ErrHnd: lblMsgMgr = "Data transfer unsuccessful . . ." lblMsgMgr = Err.Description If MSCommI.PortOpen = True Then MSCommI.PortOpen = False End Sub Private Sub device2pc() On Error GoTo ErrHnd Call doOpen_CommPort Dim ff As Integer Dim pvCtr As Integer Dim oneChr As String Dim totChr As Integer Dim curRec As String Dim totRec As Integer Dim recLen As Integer lblMsgMgr = "Waiting for request . . ." Do DoEvents oneChr = MSCommI.Input Loop While oneChr <> "$" MSCommI.InBufferCount = 0 MSCommI.Output = "@" lblMsgMgr = "Sending response . . ." totRec = 0 For pvCtr = 1 To 4 Do DoEvents Loop While MSCommI.InBufferCount = 0 oneChr = MSCommI.Input totRec = (totRec * 10) + Val(oneChr) Next pvCtr recLen = 0 For pvCtr = 1 To 3 Do DoEvents Loop While MSCommI.InBufferCount = 0 oneChr = MSCommI.Input recLen = (recLen * 10) + Val(oneChr) Next pvCtr ff = FreeFile Open txtFile For Output As #ff lblMsgMgr = "Total no of records is " & totRec & " of " & recLen & " byte each" MSCommI.Output = "!" pvCtr = 0 Do 'Started to receive records totChr = 0 curRec = "" Do oneChr = "" Do DoEvents Loop While MSCommI.InBufferCount = 0 oneChr = MSCommI.Input If oneChr = Chr(10) Then Exit Do curRec = curRec & oneChr totChr = totChr + 1 Loop While True Print #ff, curRec lblStatus = pvCtr: lblStatus.Refresh MSCommI.Output = "#" pvCtr = pvCtr + 1 Loop While pvCtr < totRec Close #ff lblMsgMgr = "Transfer of data from device to pc completed" Call doShut_CommPort Exit Sub ErrHnd: lblMsgMgr = Err.Description If MSCommI.PortOpen = True Then MSCommI.PortOpen = False End Sub Private Sub TransferThisString(vStr As String, vWait4MS As Integer) On Error GoTo ErrHnd Dim vLen As Integer Dim vCtr As Integer vLen = Len(vStr) For vCtr = 1 To vLen Do If MSCommI.OutBufferCount = 0 Then _ Exit Do Loop If vWait4MS <> 0 Then JustWaitFor vWait4MS MSCommI.Output = Mid(vStr, vCtr, 1) Next vCtr ErrHnd: End Sub Private Sub AddEventInList() 'santosh lstEvents.AddItem lblMsgMgr End Sub Private Sub WaitForSecs(vSeconds As Integer) Sleep vSeconds * 1000 End Sub Private Sub JustWaitFor(vMiliSec As Integer) Sleep vMiliSec End Sub Private Sub doShut_CommPort() On Error GoTo ErrHnd If MSCommI.PortOpen = True Then _ MSCommI.PortOpen = False Exit Sub ErrHnd: Err.Raise 12345, , "Error in closing port" End Sub Private Sub doOpen_CommPort() On Error GoTo ErrHnd Dim vStr As String Dim vDataBit As String Dim vStopBit As String vDataBit = 8 'Can be taken as a parameter vStopBit = 1 'Can be taken as a parameter vStr = "Error in setting port . . ." MSCommI.CommPort = Val(cmbPort) vStr = "Error in setting input/output parameters . . ." MSCommI.InputLen = 1 MSCommI.InBufferCount = 0 MSCommI.OutBufferCount = 0 vStr = "Error in setting braud rate . . ." MSCommI.Settings = "57600,N," & vDataBit & "," & vStopaBit '57600,N,8,1 vStr = "Error in setting input mode . . ." MSCommI.InputMode = comInputModeText vStr = "Error in opening port . . ." If MSCommI.PortOpen = True Then _ MSCommI.PortOpen = False MSCommI.PortOpen = True Exit Sub ErrHnd: Err.Raise 12345, , vStr End Sub Private Sub lblMsgMgr_Change() lblStatus = lblMsgMgr lstEvents.AddItem lblMsgMgr lstEvents.ListIndex = lstEvents.ListCount - 1 Refresh End Sub Compact And Repair an MDB fileWhen insert and deletion happens to mdb files, insertion increases the file size but deletion doesn’t reduce it. It requires repairing. If you do action called ‘compact and repair’ from within Microsoft Access, it may take hours. The following visual basic code can do the same quickly. This code requires a reference of ‘Microsoft Jet and Replication Objects 2.6 Library’ Private Sub DoCompactAndRepair() On Error GoTo ErrHnd lblActionMsg.Visible = True Dim vMyAccDB, vMyTmpDB, vMyAccPath, vMyTmpPath vMyAccDB = App.Path & "\" & "MyAccDB.mdb" vMyTmpDB = App.Path & "\" & "MyTmpDB.mdb" Refresh If Dir(vMyTmpDB) <> "" Then Kill vMyTmpDB Dim vMSJetAndReplicationObj As JRO.JetEngine Set vMSJetAndReplicationObj = New JRO.JetEngine vMyAccPath = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" vMyAccPath = vMyAccPath & vMyAccDB & ";Jet OLEDB:Database Password=MyPwd" vMyTmpPath = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" vMyTmpPath = vMyTmpPath & vMyTmpDB & ";Jet OLEDB:Database Password=MyPwd" vMSJetAndReplicationObj.CompactDatabase vMyAccPath, vMyTmpPath Kill vMyAccDB Name vMyTmpDB As vMyAccDB lblActionMsg = "Done" GoTo EndSmt ErrHnd: lblActionMsg = Err.Number & " " & Err.Description EndSmt: Screen.MousePointer = vbDefault End Sub Sending an email using MAPIHave you ever thought it would be great to be able to send email from a Visual Basic program? With Visual Basic's MAPI controls, it's a snap. These two controls let you send messages on any MAPI-compliant email system, such as Outlook and Exchange. To use the MAPI controls, you must select them in your project's Components dialog box. They are listed as "Microsoft MAPI Controls 6.0." The two controls will then appear in your toolbox; they are called MAPISession and MAPIMessages. Place one of each on a form - they are invisible at runtime. The MAPISession control is used to establish a session, or connection, with whatever MAPI-compliant mail software is installed on the system. The control has UserName and Password properties for signing onto an email account. You can set these properties at design time or prompt the user for them in code. Then, call the control's SignOn method to establish the session. Once the session is established, the control's SessionID property returns a handle of the session. The MAPIMessages control must be passed the handle of the MAPI session, obtained from the MAPISession control's SessionID property. Once this is done, the MAPIMessages control can be used for various tasks such as accessing messages in the InBox, saving, copying and deleting messages, and working with attachments. For this tip we are interested in creating and sending messages. This requires the following steps: 1. Call the Compose method to create a new message. 2. Put the recipient, the subject, and the body of the message in the corresponding control properties. 3. Call the Resolve method to verify the message recipient. 4. Call the Send method to send the message. Sending a message with the MAPIMessages control does not literally send it, but puts it in the Outbox of the mail system. When the message is actually sent depends on the mail system settings. When your program is finished with mail-related activities, call the MAPISession control's SignOff method to terminate the session. The following code demonstrates this. It assumes that the form containing the code contains TextBox controls for the various bits of information needed: user name, password, etc. Private Sub SendMail_Click() MAPISession1.UserName = tstUserName.Text MAPISession1.Password = txtPassword.Text MAPISession1.SignOn MAPIMessages1.SessionID = MAPISession1.SessionID MAPIMessages1.Compose MAPIMessages1.RecipAddress = txtTo.Text MAPIMessages1.MsgSubject = txtSubject.Text MAPIMessages1.MsgNoteText = txtMessage.Text MAPIMessages1.ResolveName MAPIMessages1.Send MAPISession1.SignOff End Sub An alternate way to use the Send method is to pass an argument with the value True (the default for this argument is False, that's why it is not included in the code above). MAPIMessages1.Send True In this case, the Send method displays a message dialog box in which the user can enter or edit the elements of the message and then send it by clicking the Send button. When a Visual Basic program needs to send email messages, perhaps for support or licensing issues, it's a lot nicer to integrate email support in the program rather than requiring the user to switch to their own email software. Ref: http://www.pgacon.com/visualbasic.htm Removing duplicate records
The above coding will work with following controls »»»»»»» by Santosh Kumar ? Original @ http://santu4you.spaces.live.com Moving a window using outside title barConst HTCAPTION = 2
»»»»»»» by Santosh Kumar ? Original @ http://santu4you.spaces.live.comBest Connection method for oracle database Hell: MsgBox "Error : " & Err.Number & vbCrLf & Err.Description End Sub Doing a 'select * from tab'Private Sub Command1_Click() Dim c As New ADODB.Connection Dim r As New ADODB.Recordset c.Open "driver={microsoft access driver (*.mdb)};dbq=F:\test.mdb;uid=;pwd=mypwd" Set r = c.OpenSchema(adSchemaTables, Array(Empty, Empty, Empty, "Table")) 'ms access Set r = c.OpenSchema(adSchemaTables, Array("Pubs", Empty, Empty, "Table")) 'sql srv While Not r.EOF Debug.Print r!TABLE_NAME r.MoveNext Wend End Sub
»»»»»»» by Santosh Kumar ? Original @ http://santu4you.spaces.live.com Visual Basic, Spelling an amount'Option Explicit Option Explicit Dim vArr1() As Variant Dim vArr2() As Variant Dim vArr3() As Variant 'Option Explicit Private Function pGet(vVal As Integer, vPos As Integer) As String
If vVal < 20 Then pGet = vArr1(vVal) Else pGet = vArr2(Left(vVal, 1)) & " " & vArr1(Right(vVal, 1)) End If pGet = Trim(pGet) If pGet <> "" Then pGet = pGet & " " & vArr3(vPos) If vPos <> 0 Then pGet = pGet & " " End If End Function Public Function AmtInRs(Optional Number As Variant) As String
On Error GoTo eHnd If Number > 10000000000000# Then _ Err.Raise 12345, , "Too big amount" If Number = "" Then _ GoTo sEnd If Not IsNumeric(Number) Then _ Err.Raise 12345, , "Non numeric value" Call FuncInit Dim vStr As String Dim nStr As String Dim vRsPs() As String Dim vRs As String Dim vPs As String Dim vBr As Integer Dim vSz As Integer Dim vWht As Boolean nStr = Number vWht = IIf(InStr(1, nStr, "-"), True, False) nStr = Replace(nStr, "-", "") vSz = 14 nStr = Format(Val(nStr), "0.00") vRsPs = Split(nStr, ".") vRs = Right(String(15, "0") & vRsPs(0), vSz) vPs = vRsPs(1) vStr = "" vBr = Mid(vRs, vSz - 13, 2): vStr = vStr & pGet(vBr, 3) vBr = Mid(vRs, vSz - 11, 2): vStr = vStr & pGet(vBr, 2) vBr = Mid(vRs, vSz - 9, 1): vStr = vStr & pGet(vBr, 1) vBr = Mid(vRs, vSz - 8, 2): vStr = vStr & pGet(vBr, 4) If vStr <> "" And InStr(1, vStr, "CRORE") = 0 Then vStr = vStr & "CRORE " vBr = Mid(vRs, vSz - 6, 2): vStr = vStr & pGet(vBr, 3) vBr = Mid(vRs, vSz - 4, 2): vStr = vStr & pGet(vBr, 2) vBr = Mid(vRs, vSz - 2, 1): vStr = vStr & pGet(vBr, 1) vBr = Mid(vRs, vSz - 1, 2): vStr = vStr & pGet(vBr, 0) If vStr = "" Then vStr = "ZERO " vBr = vPs vStr = "RUPEES " & vStr & "AND PAISE " & IIf(vBr = 0, "ZERO ", pGet(vBr, 0)) & "ONLY" vStr = StrConv(vStr, vbProperCase) If vWht Then vStr = "(" & vStr & ")" GoTo sEnd eHnd:
vStr = "Can't handle" sEnd:
AmtInRs = vStr End Function Private Sub FuncInit()
vArr1 = Array("", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE", "TEN", "ELEVEN", "TWELVE", "THIRTEEN", "FOURTEEN", "FIFTEEN", "SIXTEEN", "SEVENTEEN", "EIGHTEEN", "NINETEEN") vArr2 = Array("", "", "TWENTY", "THIRTY", "FORTY", "FIFTY", "SIXTY", "SEVENTY", "EIGHTY", "NINETY") vArr3 = Array("", "HUNDRED", "THOUSAND", "LAKH", "CRORE") End Sub
»»»»»»» by Santosh Kumar ? Original @ http://santu4you.spaces.live.com Reading an entire filePublic Function ppGetTextFileData(bvFile As String) As String
Dim ff As Integer
ff = FreeFile Open bvFile For Input As ff ppGetTextFileData = Input(LOF(ff), #ff) Close ff End Function »»»»»»» by Santosh Kumar ? Original @ http://santu4you.spaces.live.com Visual Basic, Dedicated process in ShellPrivate Declare Function _
OpenProcess Lib "kernel32" ( _ ByVal dwDesiredAccess As Long, _ ByVal bInheritHandle As Long, _ ByVal dwProcessId As Long _ ) As Long Private Declare Function _
WaitForSingleObject Lib "kernel32" ( _ ByVal hHandle As Long, _ ByVal dwMilliseconds As Long _ ) As Long Private Function ShellAndWait(ProgramName As String) As Long
Const SYNCHRONIZE = &H100000 Const INFINITE = &HFFFF Dim hHandle As Long Dim PID As Long PID = Shell(ProgramName, vbHide) If PID <> 0 Then hHandle = OpenProcess(SYNCHRONIZE, 0&, PID) WaitForSingleObject hHandle, INFINITE End If ShellAndWait = PID End Function Private Sub Command1_Click
ShellAndWait "imp tmp/tmp@ora8i file=c:\usr.dmp tables=(tab1,tab2,tab3)" End Sub Visual Basic, Execute a line of code stored in a stringFunction FExecuteCode(stCode As String, Optional fCheckOnly As Boolean) As Boolean
FExecuteCode = EbExecuteLine(StrPtr(stCode), 0&, 0&, Abs(fCheckOnly)) = 0
End Function
Private Sub Command1_Click()
Dim res As Boolean
res = FExecuteCode(Text1.Text)
Label1.Caption = "Status = " & res
End Sub
»»»»»»» by Santosh Kumar ? Original @ http://santu4you.spaces.live.com Visual Basic, Listing printers For Each vPrn In Printers
Debug.Print vPrn.DeviceName
Next
»»»»»»» by Santosh Kumar ? Original @ http://santu4you.spaces.live.com |
|
|