Page 1 of 2 12 LastLast
Results 1 to 40 of 43

Thread: [EDITED - New Errors] Help needed for Project!!

  1. #1

    Thread Starter
    Lively Member FiOh's Avatar
    Join Date
    Sep 2006
    Location
    Another World
    Posts
    104

    Exclamation [EDITED - New Errors] Help needed for Project!!

    Hi there,
    I'm new to VB but needs to write a program with VB for my project.

    My project is to write an application that will check if it's being run on a valid user by reading the PC Name. Next it will allow valid user to select the folder to map to. Drive to map will be W:, X: and Y:, folder to map to will be \\netapp\xxx (got a list of different sub-folders in netapp server to be map to). It also allows valid user to select the 'CustomerCode' and Program to Launch'.

    I am using combo for user to select the items in mapping server, customer code, device type and tester platform. But the problem is everything (the date) is store in a text (.txt) file. And i am supposed to get the data from the text file and put it into the different combos as the items accordingly.
    If the folder have already been mapped before, it should un-map it first then allow user to map again. When user close the application, the application should unmap whichever folder the user has mapped earlier.


    I am not supposed to hardcode the network to map in the program, need to read the server to map from the config.txt file. This program is not supposed to hardcode anything in it. All data are to be read from the same config.txt file. So that when there is a need to modify the program, we only need to modify the data in the config.txt file instead of going to the VB project and change the codings in the application.

    Edited Part:
    Now that i have most of the problems solved, but i need to modify this program so that i can have a complete workable program.

    Here's the question:

    1) How to apply the same technique used on the cboCusCode combo (retrieve the customer code from .txt file) on the cboMapServer as well as on the cboProgram combos?

    This is because we realised that when we choose CusCode 'SM4', the program to launch will only be 'STMP35XX_FT' and its being repeated 3 times. The correct programs selection in the cboProgram when user select the 'SM4' of the customer code should be 'STMP35XX_FT', 'STMP35XX_WS' & 'NON_STMP35XX_FT'.

    2) How do i hide (don't show) the cboProgram and lblProgram (the Program to Launch label and the combo to select item in it.) and disable the cboMapServer (Server to map combo) and cboCusCode (Customer Code) when the program is being run on a invalid platform (from pc name)?

    I have attached the Program Coding in a .doc file, the configfile.txt and Interface of the Program on a valid tester as well as on invalid tester (Images).

    - NPL_Interface.JPG (On Valid Tester)
    - NPL_Interface2.JPG (On Invalid Tester)
    - ProgramCodign.doc (Word Document)
    Attached Images Attached Images   
    Attached Files Attached Files
    Last edited by FiOh; Oct 15th, 2006 at 08:07 PM. Reason: New Errors occur
    || ~ * FiOh * ~ ||

    Different personality n character... alone,
    difficult to understand n mysterious,
    for I am... Princess Cindistine @ Another World.
    You should know...
    P.C - R.N.A.F. Yeah, that is ME...

  2. #2

    Thread Starter
    Lively Member FiOh's Avatar
    Join Date
    Sep 2006
    Location
    Another World
    Posts
    104

    Re: Help needed for Project!!

    Do i need to declare anything? Like the objFSO?
    || ~ * FiOh * ~ ||

    Different personality n character... alone,
    difficult to understand n mysterious,
    for I am... Princess Cindistine @ Another World.
    You should know...
    P.C - R.N.A.F. Yeah, that is ME...

  3. #3
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Help needed for Project!!

    Nothing Just Check the Button "The Microsoft Scripting Runtime" from the Reference menu

  4. #4

    Thread Starter
    Lively Member FiOh's Avatar
    Join Date
    Sep 2006
    Location
    Another World
    Posts
    104

    Re: Help needed for Project!!

    But there's a compile error saying variable not defined, highlighted objFSO.
    How abt this, i post the coding i have done so far.

    VB Code:
    1. Option Explicit
    2.  
    3. '1st 2 lines For No-resize form
    4. Private dex As Long ' Declare variable dex as Long & Private
    5. Private dey As Long ' Declare variable dey as Long & Private
    6.  
    7. Private Const ERROR_SUCCESS         As Long = 0
    8. Private Const MAX_DOMAIN_NAME_LEN   As Long = 128
    9. Private Const MAX_HOSTNAME_LEN      As Long = 128
    10. Private Const MAX_SCOPE_ID_LEN      As Long = 256
    11.  
    12. Private Type IP_ADDRESS_STRING
    13.     IpAddr(0 To 15)  As Byte
    14. End Type
    15.  
    16. Private Type IP_MASK_STRING
    17.     IpMask(0 To 15)  As Byte
    18. End Type
    19.  
    20. Private Type IP_ADDR_STRING
    21.     dwNext     As Long
    22.     IpAddress  As IP_ADDRESS_STRING
    23.     IpMask     As IP_MASK_STRING
    24.     dwContext  As Long
    25. End Type
    26.  
    27. Private Type FIXED_INFO
    28.   HostName(0 To (MAX_HOSTNAME_LEN + 3))         As Byte
    29.   DomainName(0 To (MAX_DOMAIN_NAME_LEN + 3))    As Byte
    30.   CurrentDnsServer   As IP_ADDR_STRING
    31.   DnsServerList      As IP_ADDR_STRING
    32.   NodeType           As Long
    33.   ScopeId(0 To (MAX_SCOPE_ID_LEN + 3))          As Byte
    34.   EnableRouting      As Long
    35.   EnableProxy        As Long
    36.   EnableDns          As Long
    37. End Type
    38.  
    39. Private Declare Function GetNetworkParams Lib "iphlpapi.dll" _
    40.   (pFixedInfo As Any, _
    41.    pOutBufLen As Long) As Long
    42.  
    43. Private Declare Sub CopyMemory Lib "kernel32" _
    44.    Alias "RtlMoveMemory" _
    45.   (Destination As Any, _
    46.    Source As Any, _
    47.    ByVal Length As Long)
    48.    
    49. 'Declaration for map drive function
    50. Private Declare Function WNetAddConnection Lib "mpr.dll" Alias "WNetAddConnectionA" (ByVal lpszNetPath As String, ByVal lpszPassword As String, ByVal lpszLocalName As String) As Long
    51.     Const WN_SUCCESS = 0 ' The function was successful.
    52.     Const WN_NET_ERROR = 2 ' An error occurred on the network.
    53.     Const WN_BAD_PASSWORD = 6 ' The password was invalid.
    54.  
    55.  
    56.  
    57. Private Sub cmdExit_Click()
    58.     End
    59. End Sub
    60.  
    61.  
    62. Private Sub cmdOK_Click()
    63.    
    64.     If cboMapServer.ListIndex = -1 Then
    65.         MsgBox "Please Select a Server to Map!!", 64, "Information"
    66.         cboMapServer.SetFocus
    67.     'Exit Sub
    68.     Else
    69.         If cboCusCode.ListIndex = -1 Then
    70.             MsgBox "Please Select a Customer Code!!", 64, "Information"
    71.             cboCusCode.SetFocus
    72.     'Exit Sub
    73.         Else
    74.             If cboDeviceType.ListIndex = -1 Then
    75.                 MsgBox "Please Select a Device Type!!", 64, "Information"
    76.                 cboDeviceType.SetFocus
    77.     'Exit Sub
    78.             Else
    79.                 If cboTester.ListIndex = -1 Then
    80.                 MsgBox "Please Select a Tester Platform!!", 64, "Information"
    81.                 cboTester.SetFocus
    82.     'Exit Sub
    83.                 End If
    84.             End If
    85.         End If
    86.     End If
    87.    
    88.     'Function to map drive
    89.     Call MAP_DRIVE
    90.    
    91. End Sub
    92.  
    93. Private Sub cmdTest_Click()
    94.     'txtStatus.Refresh
    95.     txtStatus = ""
    96.     Dim mydata As String
    97.     Open "C:\Documents and Settings\IA1\My Documents\MyVBWorks\configtest.txt" For Input As 1
    98.     While EOF(1) = False
    99.     Line Input #1, mydata
    100.     txtStatus = txtStatus & mydata & vbCrLf
    101.     cboCusCode.AddItem mydata
    102.     Wend
    103.     Close 1
    104. End Sub
    105.  
    106. Private Sub Form_Load()
    107.     'Check for valid tester
    108.     'If GetHostName = "J750" Or "UFLEX" Or "IFLEX" Then
    109.     'MsgBox "Hi" + GetHostName + "U are not running on a valid tester platform."
    110.     'End If
    111.    
    112.      
    113.     dex = Me.Height ' Set dex equal to Form Height
    114.     dey = Me.Width  ' Set dey equal to Form Width
    115.  
    116.     'Center the form on screen
    117.     Me.Move (Screen.Width - Me.Width) \ 2, (Screen.Height - Me.Height) \ 2
    118.  
    119.     'Alternate method
    120.     'CentreForm Me
    121.    
    122.     'To display the PC Name
    123.     lblPCName = GetHostName()
    124.    
    125.     'Add items for Mapping Server
    126.      cboMapServer.AddItem "Netapp"
    127.    
    128.     'Add items for Customer Code Combo List
    129.      Dim mydata As String
    130.     Open "C:\Documents and Settings\IA1\My Documents\MyVBWorks\CusCode.txt" For Input As 1
    131.     While EOF(1) = False
    132.     Line Input #1, mydata
    133.     cboCusCode.AddItem mydata
    134.     Wend
    135.     Close 1
    136.    
    137.     'Add items for Device Type Combo List
    138.      Dim mydata2 As String
    139.     Open "C:\Documents and Settings\IA1\My Documents\MyVBWorks\Device.txt" For Input As 1
    140.     While EOF(1) = False
    141.     Line Input #1, mydata2
    142.     cboDeviceType.AddItem mydata2
    143.     Wend
    144.     Close 1
    145.    
    146.     'Add items for Tester/Platform Combo List
    147.     Dim mydata3 As String
    148.     Open "C:\Documents and Settings\IA1\My Documents\MyVBWorks\Tester.txt" For Input As 1
    149.     While EOF(1) = False
    150.     Line Input #1, mydata3
    151.     cboTester.AddItem mydata3
    152.     Wend
    153.     Close 1
    154.    
    155.  
    156. End Sub
    157.  
    158. Public Function GetHostName() As String
    159.  
    160.    Dim buff()        As Byte
    161.    Dim cbRequired    As Long
    162.    Dim nStructSize   As Long
    163.    Dim Info          As FIXED_INFO
    164.  
    165.   'Call the api passing null as pFixedInfo.
    166.   'The required size of the buffer for the
    167.   'data is returned in cbRequired
    168.    Call GetNetworkParams(ByVal 0&, cbRequired)
    169.  
    170.    If cbRequired > 0 Then
    171.    
    172.      'create a buffer of the needed size
    173.       ReDim buff(0 To cbRequired - 1) As Byte
    174.      
    175.      'and call again
    176.       If GetNetworkParams(buff(0), cbRequired) = ERROR_SUCCESS Then
    177.              
    178.         'copy the buffer into a FIXED_INFO type
    179.          CopyMemory Info, ByVal VarPtr(buff(0)), LenB(Info)
    180.            
    181.         'and retrieve the host name
    182.          GetHostName = TrimNull(StrConv(Info.HostName, vbUnicode))
    183.      
    184.       End If  'If GetNetworkParams
    185.    End If  'If cbRequired > 0
    186.  
    187. End Function
    188.  
    189. Private Function TrimNull(item As String)
    190.  
    191.     Dim pos As Integer
    192.    
    193.    'double check that there is a chr$(0) in the string
    194.     pos = InStr(item, Chr$(0))
    195.     If pos Then
    196.        TrimNull = Left$(item, pos - 1)
    197.     Else
    198.        TrimNull = item
    199.     End If
    200.  
    201. End Function
    202.  
    203. Private Sub Form_Resize()
    204.  
    205.     On Error Resume Next ' Bypass the error 384. Occurs in Maximized, Minimized or restored mode.
    206.     Me.Height = dex      ' Set the Form Height equal to dex initial in Form_Load()
    207.     Me.Width = dey       ' Set the Form Width equal to dey initial in Form_Load()
    208.  
    209. End Sub
    210.  
    211.  
    212. Private Sub MAP_DRIVE()
    213.    
    214.     Dim strPassword As String
    215.     Dim strLocalDriveLetter As String 'New
    216.     Dim strNetworkPathName As String 'New
    217.    
    218.     txtStatus = "Mapping in Process..."
    219.     Screen.MousePointer = vbHourglass
    220.    
    221.     strLocalDriveLetter = "Y:" 'cboMapServer.Text 'Local drive letter to be mapped
    222.     'strPassword = "password" 'specify network password if required
    223.     strNetworkPathName = "\\netapp\BC2_production" '\\Tsg999  or \\servername\Netapp or txtSourceMain.Text 'path to network drive
    224.  
    225. If WNetAddConnection(strNetworkPathName, strPassword, strLocalDriveLetter) > 0 Then
    226.     MsgBox "An Error occurred mapping the drive", 16, "Error Message"
    227.     'End
    228.     txtStatus = "Mapping Failed."
    229.     Screen.MousePointer = vbDefault
    230. Else
    231.     MsgBox txtStatus.Text & ": Drive successfully mapped!", 64, "Information"
    232.     End If
    233. End Sub
    234.  
    235. 'Fade Screen on unload
    236. Private Sub FadeScreen(pfForm As Form, pstrWhichWay As String)
    237.        
    238.         Dim sngVertical As Single
    239.         Dim sngHorizontal As Single
    240.         Dim sngMoveToRight As Single
    241.         Dim sngMoveTop As Single
    242.         Dim i As Integer
    243.         Const cnstStep = 1000
    244.        
    245.         sngVertical = pfForm.Width / cnstStep
    246.        
    247.         Select Case UCase(pstrWhichWay)
    248.           Case "TR"
    249.             'fade to top right                '
    250.             sngMoveToRight = pfForm.Height / cnstStep
    251.             sngHorizontal = sngMoveToRight
    252.           Case "BL"
    253.             'fade to bottom left
    254.             sngMoveTop = pfForm.Height / cnstStep
    255.             sngVertical = sngMoveTop
    256.             sngHorizontal = pfForm.Height / cnstStep
    257.           Case "BR"
    258.             'fade to bottom right
    259.             sngMoveTop = pfForm.Height / cnstStep
    260.             sngVertical = sngMoveTop
    261.             sngMoveToRight = pfForm.Height / cnstStep
    262.             sngHorizontal = pfForm.Height / cnstStep
    263.           Case Else
    264.             'default to top left if you put something else in
    265.             sngHorizontal = pfForm.Height / cnstStep 'size of horizontal steps
    266.         End Select
    267.        'save direction to registry
    268.        SaveSetting "FormName", "Unload Screen", "Direction", pstrWhichWay
    269.         For i = 1 To cnstStep - 1
    270.             pfForm.Move pfForm.Left + sngMoveToRight, pfForm.Top + sngMoveTop, _
    271.             pfForm.Width - sngHorizontal, pfForm.Height - sngVertical
    272.         Next
    273.        
    274.         Unload Me
    275.        
    276.     End Sub
    277.  
    278.  
    279. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    280. Dim strRegSetting As String
    281. Dim strNewDirection As String
    282. strRegSetting = GetSetting("FormName", "Unload Screen", "Direction")
    283.         If strRegSetting = vbNullString Then
    284.            FadeScreen Me, "BR"
    285.            Exit Sub
    286.         Else
    287.           Select Case strRegSetting
    288.             Case "BR"
    289.               strNewDirection = "BL"
    290.             Case "BL"
    291.               strNewDirection = "TR"
    292.             Case "TR"
    293.               strNewDirection = "BR"
    294.           End Select
    295.         End If
    296.         FadeScreen Me, strNewDirection
    297. End Sub

    My current problems are:
    1) How should i do if i want to include every data in only 1 text file and use a method to extract the part that i want from the text file to be place into my combo as the item.
    2) I need to map to the server to the \\netapp\CusCode.txt\Device.txt\Tester.txt by all reading the data from the text file yet i do not know how to do it.
    3) I do not know how do i un-map the mapped drives when the user close the application.

    Sorry for the trouble.
    || ~ * FiOh * ~ ||

    Different personality n character... alone,
    difficult to understand n mysterious,
    for I am... Princess Cindistine @ Another World.
    You should know...
    P.C - R.N.A.F. Yeah, that is ME...

  5. #5
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Help needed for Project!!

    Dear Fioh,
    Give a screen shot of you project , and brief the requirements

  6. #6

    Thread Starter
    Lively Member FiOh's Avatar
    Join Date
    Sep 2006
    Location
    Another World
    Posts
    104

    Post Re: Help needed for Project!!

    Quote Originally Posted by danasegarane
    Dear Fioh,
    Give a screen shot of you project , and brief the requirements
    This is the link for the interface of the project (Production Launcher).

    PLauncher Interface
    * Note: In the image the PC Name is to display out the name of the PC.

    Project Outline

    Objective
    To create a new Production Launcher that allows the user to be able to select the mapping location of the production and datalog network drive.

    Reason
    The current Production Launcher does not allow the user to choose the mapping location of the production and datalog network drive, it is hard coded in the program. If the user is able to select the mapping location, temporary or permanent migration of the mapping location could be done on the fly instead of modifying the program code.

    Specifications
    1.User must be able to select the mapping location, customer code, device type and tester platform.
    2.The list of mapping location & customer code will be stored in a .txt configuration file.
    3.The Production Launcher must be able to check if it’s being run on a valid tester (checking valid PC Name). For Invalid user, a of 'Hi (Name of User),
    You are at XXX (PC Name), this is not a valid tester/platform.
    Therefore you are not allow to map to our server!!!
    Any issue, pls get back to Test System Group.
    Thanks.' will appear in a pop up msg box. After the invalid user close the msg box, the Production Launcher will still be launch but all the functions of the combo and command buttons will be disabled.
    4.The Production Launcher must be able to check if the production and datalog network drive is being mapped or used.
    5.If any production and/or datalog network drive is being mapped or used, the program must be able to un-map the current mapping, before trying to map the network drive.
    6.The status of the mapping or un-mapping must be shown in a status window (The multi-line textbox).
    7.Once the mapping is done successfully, the Production UI program (another .exe application to be called) must be launched automatically.
    8.List of the Production UI program name will be stored in the same .txt configuration file as the mapping location & customer code.

    These are what my supervisor had further added in:
    - The list item in each ComboxBoxes (mapping location, customer code, device type and tester platform) should be read from a .txt file (the very same config.txt).
    - When user close the Production Launcher application, the mapped before location should be un-mapped automatically.


    Sorry for the trouble.
    ^^;
    || ~ * FiOh * ~ ||

    Different personality n character... alone,
    difficult to understand n mysterious,
    for I am... Princess Cindistine @ Another World.
    You should know...
    P.C - R.N.A.F. Yeah, that is ME...

  7. #7
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Help needed for Project!!

    whereever you want to unmap , you have to call the function
    VB Code:
    1. Call UNMAP_DRIVE

  8. #8

    Thread Starter
    Lively Member FiOh's Avatar
    Join Date
    Sep 2006
    Location
    Another World
    Posts
    104

    Post Re: Help needed for Project!!

    Quote Originally Posted by danasegarane
    whereever you want to unmap , you have to call the function
    VB Code:
    1. Call UNMAP_DRIVE
    I am given a sample text file, here is the contents:

    CustomerCode=BC1|CT8|TW3|SM4|SY1|XM1|AK1|SN2|SE2|SM1

    BC1=ProductionUI

    CT8=ProductionUI

    TW3=ProductionUI

    SM4=STMP35XX_FT|STMP35XX_WS|NON_STMP35XX_FT

    SY1=ProductionUI

    XM1=IG-XL_3.40.10_FT

    AK1=ProductionUI

    SN2=ProductionUI

    SE2=ProductionUI

    SM1=ProductionUI


    How do i upload the textfile and image here?
    The company blocked most of the sites. I cant get into my registered web host account to upload the image and textfile there for linking.

    T-T
    || ~ * FiOh * ~ ||

    Different personality n character... alone,
    difficult to understand n mysterious,
    for I am... Princess Cindistine @ Another World.
    You should know...
    P.C - R.N.A.F. Yeah, that is ME...

  9. #9
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Help needed for Project!!

    Goto the advanced button, you will get the attachment option.

  10. #10

    Thread Starter
    Lively Member FiOh's Avatar
    Join Date
    Sep 2006
    Location
    Another World
    Posts
    104

    Post Re: Help needed for Project!!

    Btw, how do i write the Call UNMAP_DRIVE function?
    I've attached the image and the text file.
    Attached Images Attached Images  
    Attached Files Attached Files
    || ~ * FiOh * ~ ||

    Different personality n character... alone,
    difficult to understand n mysterious,
    for I am... Princess Cindistine @ Another World.
    You should know...
    P.C - R.N.A.F. Yeah, that is ME...

  11. #11

    Thread Starter
    Lively Member FiOh's Avatar
    Join Date
    Sep 2006
    Location
    Another World
    Posts
    104

    Re: Help needed for Project!!

    Do i need to declare anything? Because when i run the program, the compiler error says 'User-defined type not defined' and it hightlighted 'objFSO As New FileSystemObject'.
    || ~ * FiOh * ~ ||

    Different personality n character... alone,
    difficult to understand n mysterious,
    for I am... Princess Cindistine @ Another World.
    You should know...
    P.C - R.N.A.F. Yeah, that is ME...

  12. #12

    Thread Starter
    Lively Member FiOh's Avatar
    Join Date
    Sep 2006
    Location
    Another World
    Posts
    104

    Re: Help needed for Project!!

    danasegarane,
    i still got the same compile error... 'User-defined type not defined' and it hightlighted 'objFSO As New FileSystemObject'.
    T-T
    I'm sorry that i'm causing you so much trouble.
    || ~ * FiOh * ~ ||

    Different personality n character... alone,
    difficult to understand n mysterious,
    for I am... Princess Cindistine @ Another World.
    You should know...
    P.C - R.N.A.F. Yeah, that is ME...

  13. #13
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Help needed for Project!!

    Have you done this
    VB Code:
    1. 'Select the Project Menu-->References--->Check Microsoft Scripting Run Time

  14. #14

    Thread Starter
    Lively Member FiOh's Avatar
    Join Date
    Sep 2006
    Location
    Another World
    Posts
    104

    Re: Help needed for Project!!

    Quote Originally Posted by danasegarane
    Have you done this
    VB Code:
    1. 'Select the Project Menu-->References--->Check Microsoft Scripting Run Time
    Yah, it was unchecked in the 1st place and i've checked it. But the error still appears. Is it that there is error for the installation of VB6?
    || ~ * FiOh * ~ ||

    Different personality n character... alone,
    difficult to understand n mysterious,
    for I am... Princess Cindistine @ Another World.
    You should know...
    P.C - R.N.A.F. Yeah, that is ME...

  15. #15
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Help needed for Project!!

    But I don't Get any errors.Ok change
    VB Code:
    1. Dim objFSO As New FileSystemObject
    to
    VB Code:
    1. Dim objFSO
    and try

  16. #16

    Thread Starter
    Lively Member FiOh's Avatar
    Join Date
    Sep 2006
    Location
    Another World
    Posts
    104

    Re: Help needed for Project!!

    Quote Originally Posted by danasegarane
    But I don't Get any errors.Ok change
    VB Code:
    1. Dim objFSO As New FileSystemObject
    to
    VB Code:
    1. Dim objFSO
    and try
    That objFSO has been solved but there's a new compiler error that says 'User-defined type not defined.' and it highlighted the
    VB Code:
    1. Dim Info          As FIXED_INFO
    in the 'Public Function GetHostName() As String'.

    Is there something wrong with VB6 itself?
    X_x
    || ~ * FiOh * ~ ||

    Different personality n character... alone,
    difficult to understand n mysterious,
    for I am... Princess Cindistine @ Another World.
    You should know...
    P.C - R.N.A.F. Yeah, that is ME...

  17. #17
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Help needed for Project!!

    Dear Fioh,
    You have to combine the coding of post 16 and Post 17.Then it will run without any compile Error...

  18. #18

    Thread Starter
    Lively Member FiOh's Avatar
    Join Date
    Sep 2006
    Location
    Another World
    Posts
    104

    Re: Help needed for Project!!

    Quote Originally Posted by danasegarane
    Dear Fioh,
    You have to combine the coding of post 16 and Post 17.Then it will run without any compile Error...
    Sorry for my slowness here...
    By the way, how should i modify the code for the [strNetworkPathName = "\\netapp\BC2_production"] replace the ("\\netapp\BC2_production") with the item selected in the cboMapServer?

    Also, for the invalid tester msgBox, how do i make it that each short sentence appears on a different line?

    Really sorry for the trouble here.
    ^^;
    || ~ * FiOh * ~ ||

    Different personality n character... alone,
    difficult to understand n mysterious,
    for I am... Princess Cindistine @ Another World.
    You should know...
    P.C - R.N.A.F. Yeah, that is ME...

  19. #19
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Help needed for Project!!

    For new lines use vbCrLf... like:
    VB Code:
    1. MsgBox "Hello," & vbCrLf & " World!"

  20. #20
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Help needed for Project!!

    Dear Fioh,
    Here is final coding.I am posting it as Part1 and Part2 .Combine Part1 and Part2.

    VB Code:
    1. Part1


    VB Code:
    1. Option Explicit
    2.  
    3. '1st 2 lines For No-resize form
    4. Private dex As Long ' Declare variable dex as Long & Private
    5. Private dey As Long ' Declare variable dey as Long & Private
    6.  
    7. Private Const ERROR_SUCCESS         As Long = 0
    8. Private Const MAX_DOMAIN_NAME_LEN   As Long = 128
    9. Private Const MAX_HOSTNAME_LEN      As Long = 128
    10. Private Const MAX_SCOPE_ID_LEN      As Long = 256
    11.  
    12. Private Type IP_ADDRESS_STRING
    13.     IpAddr(0 To 15)  As Byte
    14. End Type
    15.  
    16. Private Type IP_MASK_STRING
    17.     IpMask(0 To 15)  As Byte
    18. End Type
    19.  
    20. Private Type IP_ADDR_STRING
    21.     dwNext     As Long
    22.     IpAddress  As IP_ADDRESS_STRING
    23.     IpMask     As IP_MASK_STRING
    24.     dwContext  As Long
    25. End Type
    26.  
    27. Private Type FIXED_INFO
    28.   hostname(0 To (MAX_HOSTNAME_LEN + 3))         As Byte
    29.   DomainName(0 To (MAX_DOMAIN_NAME_LEN + 3))    As Byte
    30.   CurrentDnsServer   As IP_ADDR_STRING
    31.   DnsServerList      As IP_ADDR_STRING
    32.   NodeType           As Long
    33.   ScopeId(0 To (MAX_SCOPE_ID_LEN + 3))          As Byte
    34.   EnableRouting      As Long
    35.   EnableProxy        As Long
    36.   EnableDns          As Long
    37. End Type
    38.  
    39. Private Declare Function GetNetworkParams Lib "iphlpapi.dll" _
    40.   (pFixedInfo As Any, _
    41.    pOutBufLen As Long) As Long
    42.  
    43. Private Declare Sub CopyMemory Lib "kernel32" _
    44.    Alias "RtlMoveMemory" _
    45.   (Destination As Any, _
    46.    Source As Any, _
    47.    ByVal Length As Long)
    48.    
    49. 'Declaration for map drive function
    50. Private Declare Function WNetAddConnection Lib "mpr.dll" Alias "WNetAddConnectionA" (ByVal lpszNetPath As String, ByVal lpszPassword As String, ByVal lpszLocalName As String) As Long
    51.     Const WN_SUCCESS = 0 ' The function was successful.
    52.     Const WN_NET_ERROR = 2 ' An error occurred on the network.
    53.     Const WN_BAD_PASSWORD = 6 ' The password was invalid.
    54. Private Declare Function WNetCancelConnection Lib "mpr.dll" Alias "WNetCancelConnectionA" (ByVal lpszName As String, ByVal bForce As Long) As Long
    55. Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias _
    56.     "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, _
    57.     ByVal lpBuffer As String) As Long
    58. Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" _
    59.     (ByVal nDrive As String) As Long
    60. Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) 'suspends for process for some time
    61. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    62. 'Const Machines = "J750_XX,UFLEX_XX,IFLEX_XX, TSG999_XX" 'To store the valid platform machine numbers.
    63. Const Machines = "J750-,UFLEX,IFLEX,is-s349a"
    64. 'you can add your machine numbers here
    65. Const FORMAT_MESSAGE_ALLOCATE_BUFFER = &H100
    66. Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000
    67. Const LANG_NEUTRAL = &H0
    68. Const SUBLANG_DEFAULT = &H1
    69. Const ERROR_BAD_USERNAME = 2202&
    70. Private Declare Function GetLastError Lib "kernel32" () As Long
    71. Private Declare Sub SetLastError Lib "kernel32" (ByVal dwErrCode As Long)
    72. Private Declare Function FormatMessage Lib "kernel32" Alias "FormatMessageA" (ByVal dwFlags As Long, lpSource As Any, ByVal dwMessageId As Long, ByVal dwLanguageId As Long, ByVal lpBuffer As String, ByVal nSize As Long, Arguments As Long) As Long
    73.  
    74. Dim custname As String
    75. Dim validtester As String
    76. Private Const CB_FINDSTRINGEXACT = &H158 'constant varriable for find the value in the combo box
    77.  
    78. 'New codes
    79. Private Const ERROR_BAD_NETPATH = 53&
    80. Private Const ERROR_NETWORK_ACCESS_DENIED = 65&
    81. Private Const ERROR_INVALID_PASSWORD = 86&
    82. Private Const ERROR_NETWORK_BUSY = 54&
    83. Dim StartFlag As Boolean
    84. 'For running the Version exe and wait untill it finishes --start
    85. Private Type STARTUPINFO
    86.    cb As Long
    87.    lpReserved As String
    88.    lpDesktop As String
    89.    lpTitle As String
    90.    dwX As Long
    91.    dwY As Long
    92.    dwXSize As Long
    93.    dwYSize As Long
    94.    dwXCountChars As Long
    95.    dwYCountChars As Long
    96.    dwFillAttribute As Long
    97.    dwFlags As Long
    98.    wShowWindow As Integer
    99.    cbReserved2 As Integer
    100.    lpReserved2 As Long
    101.    hStdInput As Long
    102.    hStdOutput As Long
    103.    hStdError As Long
    104. End Type
    105.  
    106. Private Type PROCESS_INFORMATION
    107.    hProcess As Long
    108.    hThread As Long
    109.    dwProcessID As Long
    110.    dwThreadID As Long
    111. End Type
    112. Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
    113.    hHandle As Long, ByVal dwMilliseconds As Long) As Long
    114.  
    115. Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
    116.    lpApplicationName As Long, ByVal lpCommandLine As String, ByVal _
    117.    lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
    118.    ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
    119.    ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _
    120.    lpStartupInfo As STARTUPINFO, lpProcessInformation As _
    121.    PROCESS_INFORMATION) As Long
    122.  
    123. Private Declare Function CloseHandle Lib "kernel32" _
    124.    (ByVal hObject As Long) As Long
    125.  
    126. Private Declare Function GetExitCodeProcess Lib "kernel32" _
    127.    (ByVal hProcess As Long, lpExitCode As Long) As Long
    128.  
    129. Private Const NORMAL_PRIORITY_CLASS = &H20&
    130. Private Const INFINITE = -1&
    131. Private Const XL_VersionExePath As String = "C:\Program Files\Teradyne\IG-XL\3.40.09\bin\versionselector.exe"
    132. 'For running the Version exe and wait untill it finishes --End
    133.  
    134.  
    135.  
    136. Private Sub cboMapServer_Click()
    137.     Dim Findpos As Integer
    138.     Dim strtext As String
    139.     strtext = "Please Select a Server to Map"
    140.     If StartFlag = True Then
    141.         Exit Sub
    142.     Else
    143.         If Trim(cbomapserver.Text) = "Please Select a Server to Map" Then
    144.            Exit Sub
    145.         Else
    146.            Findpos = SendMessage(cbomapserver.hwnd, CB_FINDSTRINGEXACT, -1, ByVal strtext)
    147.            If Findpos > -1 Then
    148.               cbomapserver.RemoveItem Findpos
    149.            End If
    150.         End If
    151.     End If
    152. End Sub
    153.  
    154. Private Sub cboprogram_Click()
    155.     Dim Findpos As Integer
    156.     Dim strtext As String
    157.     strtext = "Please Select a Program to Launch"
    158.     If StartFlag = True Then
    159.         Exit Sub
    160.     Else
    161.         If Trim(cboProgram.Text) = "Please Select a Program to Launch" Then
    162.             Exit Sub
    163.         Else
    164.               Findpos = SendMessage(cboProgram.hwnd, CB_FINDSTRINGEXACT, -1, ByVal strtext)
    165.              If Findpos > -1 Then
    166.               cboProgram.RemoveItem Findpos
    167.              End If
    168.              If Trim(cboProgram.Text) <> "Please Select a Program to Launch" Then
    169.                 lbl_version.Caption = cboversion.List(cboProgram.ListIndex)
    170.              End If
    171.              
    172.         End If
    173.     End If
    174. End Sub
    175.  
    176. Private Sub cmdExit_Click()
    177.     'For Ending the program
    178.     End
    179. End Sub
    Last edited by danasegarane; Nov 5th, 2006 at 11:25 PM.

  21. #21
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Help needed for Project!!

    VB Code:
    1. Part2

    VB Code:
    1. Private Sub cboCusCode_Click()
    2.     Dim Findpos As Integer
    3.     Dim strtext As String
    4.     'to get the custname
    5.      Dim strposition As Integer ' For finding the postion of program code in program combo
    6.      Dim objCust    'for opening the text file and search for custumer code
    7.      Dim objCust1   'for opening the text file
    8.      Dim strline    'to read the text file as lineby line
    9.      Dim custcode As String 'for storing the custumer code
    10.      Dim programname As String  'for finding the program code in the program combo
    11.      Dim sVersion As String
    12.      Dim i As Integer
    13.      Dim strcustumernew
    14.      custcode = Trim(cbocuscode.Text) & "="   'for stroing the custumer code
    15.      Set objCust = CreateObject("Scripting.FileSystemObject")
    16.      'Real tester path
    17.     Set objCust1 = objCust.OpenTextFile("C:\testsys\configfile.txt", 1)
    18.      
    19.      'Set objCust1 = objCust.OpenTextFile("D:\test\configfile.txt", 1)
    20.      'Set objCust1 = objCust.OpenTextFile("C:\Documents and Settings\IA1\My Documents\configfile.txt", 1)
    21.       'Set objCust1 = objCust.OpenTextFile("C:\configfile.txt", 1) 'open text file for reading
    22.       cboProgram.Clear  'clear the cboprogram Entries
    23.       lbl_version.Caption = ""
    24.         cboProgram.AddItem "Please Select a Program to Launch"
    25.       Do Until objCust1.AtEndOfStream   'loop through the entries in the text file.Read line by line .Untill the end of file is found
    26.          strline = objCust1.ReadLine   'read line  by line
    27.          If InStr(1, strline, custcode, vbTextCompare) > 0 Then  'search for BC1= or CT8= and so on... . if Found then the it will re
    28.          'return a value greater than 0.
    29.              'After this find cut the line program code only
    30.              'eg if CT8=ProductionUI or BC1=ProductionUI is found then only cut the part ProductionUI
    31.              custname = Right(strline, (Len(strline) - InStr(1, strline, "=", vbTextCompare)))
    32.              'if the return value is like in the format SM4=STMP35XX_FT|STMP35XX_WS|NON_STMP35XX_FT
    33.               cboversion.Clear
    34.               If InStr(1, custname, "|", vbTextCompare) > 0 Then
    35.                 ' then check the postion of | .If | found then split that string with respect to |
    36.                  strcustumernew = Split(custname, "|")
    37.                
    38.                 'Loop through the array and add the program values in the program combo
    39.                  For i = LBound(strcustumernew) To UBound(strcustumernew)
    40.                    'Get the of customers
    41.                    'Get the version
    42.                    Dim Sfindpos As Integer
    43.                    Sfindpos = InStr(1, strcustumernew(i), ",", vbTextCompare)
    44.                    If Sfindpos > 0 Then
    45.                      sVersion = Mid(strcustumernew(i), Sfindpos + 1, Len(strcustumernew(i)))
    46.                      'Add the version to a new hide combo namely cbo version
    47.                    End If
    48.                   If Len(sVersion) > 0 Then
    49.                     sVersion = sVersion
    50.                   Else
    51.                     sVersion = ""
    52.                   End If
    53.                   cboversion.AddItem sVersion, i
    54.                    'Get the Program part
    55.                    Dim Sfindpos1 As Integer
    56.                    Sfindpos1 = InStr(1, strcustumernew(i), ",", vbTextCompare)
    57.                    If Sfindpos1 > 0 Then
    58.                     programname = Left(strcustumernew(i), Sfindpos - 1) 'assign the program code in the varriable
    59.                    Else
    60.                      programname = strcustumernew(i)
    61.                    End If
    62.                    If Len(programname) > 0 Then
    63.                     programname = programname
    64.                    Else
    65.                     programname = ""
    66.                    End If
    67.                    'search code the code in the program combo.
    68.                     'if found then "strpostion" will be greater than 0 and the retrun the location of the
    69.                     'value in the program combo as either 0 or 1 or so on
    70.                    strposition = SendMessage(cboProgram.hwnd, CB_FINDSTRINGEXACT, -1, ByVal programname)
    71.                    'if not found, then the return value wiil be -1 .Then add the value in the program combo
    72.                    If strposition = -1 Then
    73.                        cboProgram.AddItem programname
    74.                    End If
    75.                  Next
    76.              Else  'same if it is like CT8=ProductionUI or BC1=ProductionUI
    77.              ' add the program code in the program combo
    78.                 strposition = SendMessage(cboProgram.hwnd, CB_FINDSTRINGEXACT, -1, ByVal custname)
    79.                 If strposition = -1 Then
    80.                 cboProgram.AddItem custname
    81.                 End If
    82.              End If
    83.          End If
    84.       Loop  'read the next line
    85.       cboProgram.ListIndex = 0
    86.    
    87.     strtext = "Please Select a Customer Code"
    88.     If StartFlag = True Then
    89.            Exit Sub
    90.     Else
    91.          
    92.         If Trim(cbocuscode.Text) = "Please Select a Customer Code" Then
    93.            Exit Sub
    94.         Else
    95.             Findpos = SendMessage(cbocuscode.hwnd, CB_FINDSTRINGEXACT, -1, ByVal strtext)
    96.              If Findpos > -1 Then
    97.               cbocuscode.RemoveItem Findpos
    98.            End If
    99.         End If
    100.     End If
    101. End Sub
    102.  
    103. Private Sub cmdOK_Click()
    104. Dim strmsg As String
    105. Dim strmsg1 As String
    106. Dim strmsg2 As String
    107.  
    108. Dim Strpath As String
    109. Dim strPassword As String
    110. Dim strLocalDriveLetter As String
    111.  
    112.  txtStatus.Text = ""
    113.  
    114.     If Trim(cbomapserver.Text) = "Please Select a Server to Map" Then
    115.         strmsg = "Mapping Server Not selected"
    116.     End If
    117.  
    118.     If Trim(cbocuscode.Text) = "Please Select a Customer Code" Then
    119.         If Trim(strmsg) <> "" Then
    120.             strmsg = strmsg & vbCrLf & "Customer Code Not Selected"
    121.         Else
    122.             strmsg = "Customer Code Not Selected"
    123.         End If
    124.     End If
    125.     If Trim(cboProgram.Text) = "Please Select a Program to Launch" Then
    126.         If Trim(strmsg) <> "" Then
    127.             strmsg = strmsg & vbCrLf & "Program to Launch Not selected"
    128.         Else
    129.             strmsg = "Program to Launch Not selected"
    130.         End If
    131.     End If
    132.     If Trim(strmsg) = "" Then
    133.    
    134.     Else
    135.     txtStatus.Text = strmsg
    136.     Exit Sub
    137.     End If
    138.     Call unmap_drives(True) 'to disconnect all the server connections
    139.    
    140.     'Function to map drive
    141.     'servername format should be in the format "\\nettapp"
    142.    ' Driveletter = cboDeviceType & ":" 'assing the drive letter
    143.        
    144.     'Call MAP_DRIVE("W:", "ip4700a", cboCusCode.Text, validtester, "_Engineering")
    145.     Screen.MousePointer = vbHourglass
    146.     Call RunXL_version(lbl_version.Caption)
    147.     Call MAP_DRIVE("W:", "168.232.32.3", cbocuscode.Text, validtester, "_Engineering") '\\Server\CustomerCode_Engineering\ValidTester\Program
    148.     Call MAP_DRIVE("X:", cbomapserver.Text, cbocuscode.Text, validtester, "_Datalog") '\\Server\CustomerCode_Datalog\ValidTester\Program
    149.     Call MAP_DRIVE("Y:", cbomapserver.Text, cbocuscode.Text, validtester, "_Production") '\\Server\CustomerCode_Production\ValidTester\Program
    150.    
    151.     Dim wpath As String
    152.     wpath = "" '-->>>fill your requirements
    153.     Screen.MousePointer = vbHourglass
    154.     Dim retval
    155.     If retval = WNetAddConnection(Strpath, strPassword, strLocalDriveLetter) > 0 Then 'Enter Path in Strpath and Password in Strpassword and Driveletter
    156.         'MsgBox "An Error occurred mapping the drive", 16, "Error Message"
    157.         'End
    158.        
    159.         txtStatus = txtStatus & vbCrLf & "Mapping to " & Strpath & vbCrLf & "An Error occurred mapping the drive." & vbCrLf & "Mapping Failed." & vbCrLf
    160.         Screen.MousePointer = vbDefault
    161.     Else
    162.         'MsgBox txtStatus.Text & ": Drive successfully mapped!", 64, "Information"
    163.         txtStatus = txtStatus & vbCrLf & "Mapping to " & Strpath & vbCrLf & "Drive successfully mapped!" & vbCrLf
    164.         Screen.MousePointer = vbDefault
    165.     End If
    166.     'This Function will Run the Correcponing exe
    167.     Call RunProgram(Trim(cbomapserver.Text), Trim(cbocuscode.Text), "_production", cboProgram.Text & ".exe")
    168.     'Disable the OK btn after mapping
    169.     cmdok.Enabled = False
    170.     'frmNPL.WindowState = vbMinimized
    171.        
    172. End Sub
    Last edited by danasegarane; Nov 5th, 2006 at 11:28 PM.

  22. #22

    Thread Starter
    Lively Member FiOh's Avatar
    Join Date
    Sep 2006
    Location
    Another World
    Posts
    104

    Re: Help needed for Project!!

    How came i can't click onto any combo or command buttons if i were to add in my current pc name (TSG999) as a new valid tester?

    Sorry to trouble you again.
    || ~ * FiOh * ~ ||

    Different personality n character... alone,
    difficult to understand n mysterious,
    for I am... Princess Cindistine @ Another World.
    You should know...
    P.C - R.N.A.F. Yeah, that is ME...

  23. #23

    Thread Starter
    Lively Member FiOh's Avatar
    Join Date
    Sep 2006
    Location
    Another World
    Posts
    104

    Re: Help needed for Project!!

    Eh, i have included the TSG999 in the Const Machines but the combos and buttons are still disabled. What is the problem?
    || ~ * FiOh * ~ ||

    Different personality n character... alone,
    difficult to understand n mysterious,
    for I am... Princess Cindistine @ Another World.
    You should know...
    P.C - R.N.A.F. Yeah, that is ME...

  24. #24
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Help needed for Project!!

    Part 3
    VB Code:
    1. Private Sub Form_Load()
    2.             Dim Strhostname As String
    3.             Dim objFSO
    4.             Dim objFile
    5.             Set objFSO = CreateObject("Scripting.FileSystemObject")
    6.             Dim strline
    7.             Dim mappingserver
    8.             Dim cust_code As String
    9.             Dim customercodes
    10.             Dim i As Integer
    11.             StartFlag = True
    12.             lblPCName = GetHostName()
    13.             txtStatus.Text = ""
    14.             'Check for valid tester
    15.            
    16.              Strhostname = GetHostName
    17.              validtester = Left(Strhostname, 5) 'assin the valid testername
    18.                 If InStr(1, Machines, validtester) = 0 Then
    19.                 MsgBox "Hi " + GetHostName + ", this is not a valid tester/platform." & vbCrLf & "Therefore you are not allow to map to our server!!!" & vbCrLf & "Any issue, pls get back to Test System Group." & vbCrLf & "Thanks.", 64, "Invalid Tester Platform"
    20.                     ' if he is not a valid user .The combo box will be disable
    21.                     ' if you wan to hide the combo box you can change this coding to " --->>>> cboprogram.visible=False
    22.                         'cboProgram.Enabled = False 'disables the program combo
    23.                         'lblProgram.Visible = False 'hide the lblprogram
    24.                         'cboProgram.Visible = False 'hide the cboprogram combo
    25.                     cboProgram.Enabled = False
    26.                     cbocuscode.Enabled = False 'disables the custcode combo
    27.                     cbomapserver.Enabled = False 'disables the cbomapserver
    28.                     cmdok.Enabled = False       'disables the cmdok combo
    29.                         'cmdExit.Enabled = False 'disables the cmdexit combo
    30.                         'Exit Sub 'exit the below coding.if you want you can comment this line
    31.                 End If
    32.            
    33.             dex = Me.Height ' Set dex equal to Form Height
    34.             dey = Me.Width  ' Set dey equal to Form Width
    35.            
    36.             'Center the form on screen
    37.             Me.Move (Screen.Width - Me.Width) \ 2, (Screen.Height - Me.Height) \ 2
    38.            
    39.             'To display the PC Name
    40.             'open the text file for reading.
    41.             'Real tester path
    42.            
    43.              
    44.              Dim fso1 As New FileSystemObject
    45.              If fso1.FileExists("C:\testsys\configfile.txt") = False Then
    46.              'If fso1.FileExists("C:\Documents and Settings\IA1\My Documents\configfile.txt") = False Then
    47.              
    48.                  cboProgram.Enabled = False
    49.                  cbocuscode.Enabled = False 'disables the custcode combo
    50.                  cbomapserver.Enabled = False 'disables the cbomapserver
    51.                  cmdok.Enabled = False
    52.                  Exit Sub
    53.                 Else
    54.              Set objFile = objFSO.OpenTextFile("C:\testsys\configfile.txt", 1)
    55.              'Set objFile = objFSO.OpenTextFile("C:\Documents and Settings\IA1\My Documents\configfile.txt", 1)
    56.              End If
    57.        
    58.                 Do Until objFile.AtEndOfStream 'read untill end of file is found
    59.                     strline = objFile.ReadLine 'read the line
    60.                     '1.......this part will add the servername code in the combox -start
    61.                     'SEARCH for string  "MappingServer="
    62.                    
    63.                     If InStr(1, strline, "MappingServer=", vbTextCompare) > 0 Then 'search for the word = , in the line
    64.                     'if found
    65.                         Dim strservers
    66.                         Dim strserver
    67.                         Dim servername As String
    68.                         Dim X
    69.                         'if found then find the return the postion of =
    70.                         'assing the value of mapping sever in the varriable
    71.                         cbomapserver.AddItem "Please Select a Server to Map"
    72.                         mappingserver = Right(strline, (Len(strline) - InStr(1, strline, "=", vbTextCompare))) 'adds the servername in the combo box
    73.                         'search for string |
    74.                         ' if found
    75.                         If InStr(1, mappingserver, "|", vbTextCompare) > 0 Then
    76.                             'spilit the string with respect to |
    77.                             strservers = Split(mappingserver, "|")
    78.                                 'loop through the array
    79.                                 For X = LBound(strservers) To UBound(strservers)
    80.                                     servername = strservers(X)
    81.                                     'find the servername in the cbo sever combo
    82.                                     strserver = SendMessage(cbomapserver.hwnd, CB_FINDSTRINGEXACT, -1, ByVal servername)
    83.                                     'if not found, then the return value wiil be -1 .Then add the value in the program combo
    84.                                         'if not not found then add the server name
    85.                                         If strserver = -1 Then
    86.                                             cbomapserver.AddItem strservers(X)
    87.                                         End If
    88.                                 Next
    89.                             Else
    90.                             '' if not found the | .Then only only one server and add that server
    91.                             servername = mappingserver
    92.                             strserver = SendMessage(cbomapserver.hwnd, CB_FINDSTRINGEXACT, -1, ByVal servername)
    93.                             'if not found, then the return value wiil be -1 .Then add the value in the program combo
    94.                                 If strserver = -1 Then
    95.                                    cbomapserver.AddItem servername
    96.                                 End If
    97.                         End If
    98.                     End If
    99.                    
    100.                     'this part will add the custmer code in the combox -start
    101.                     If InStr(1, strline, "CustomerCode=", vbTextCompare) > 0 Then 'read the custname name line
    102.                         cbocuscode.AddItem "Please Select a Customer Code"
    103.                         'search for the string "customerocode="
    104.                         cust_code = Right(strline, (Len(strline) - InStr(1, strline, "=", vbTextCompare)))
    105.                         'if the "customerocode=" string found in the strline varriable, then found the postion of |
    106.                         ' in string "CustomerCode=BC1|CT8|TW3|SM4|SY1|XM1|AK1|SN2|SE2|SM1"
    107.                         'cut the custumer codes only as "BC1|CT8|TW3|SM4|SY1|XM1|AK1|SN2|SE2|SM1"
    108.                         If InStr(1, cust_code, "|", vbTextCompare) > 0 Then
    109.                             'and split the strline varriable with respect to |
    110.                             customercodes = Split(cust_code, "|")
    111.                                 For i = LBound(customercodes) To UBound(customercodes)
    112.                                     cbocuscode.AddItem customercodes(i) 'add the custumer codes in the combo
    113.                                 Next
    114.                         End If
    115.                     End If
    116.                     ''this part will add the custmer code in the combox -End
    117.                 Loop 'read the next line
    118.            
    119.             Call unmap_drives(False) 'to display the all the mapped servers in the status list
    120.             'cboMapServer.ListIndex = 0
    121.             'cboCusCode.ListIndex = 0
    122.            
    123.             If cbomapserver.ListCount > 0 Then cbomapserver.ListIndex = 0
    124.             If cbocuscode.ListCount > 0 Then cbocuscode.ListIndex = 0
    125.  
    126.             StartFlag = False
    127.                    
    128. End Sub
    129.  
    130.  
    131. Public Function GetHostName() As String
    132. 'Function to get the host name
    133.    Dim buff()        As Byte
    134.    Dim cbRequired    As Long
    135.    Dim nStructSize   As Long
    136.    Dim Info          As FIXED_INFO
    137.  
    138.   'Call the api passing null as pFixedInfo.
    139.   'The required size of the buffer for the
    140.   'data is returned in cbRequired
    141.    Call GetNetworkParams(ByVal 0&, cbRequired)
    142.  
    143.    If cbRequired > 0 Then
    144.    
    145.      'create a buffer of the needed size
    146.       ReDim buff(0 To cbRequired - 1) As Byte
    147.      
    148.      'and call again
    149.       If GetNetworkParams(buff(0), cbRequired) = ERROR_SUCCESS Then
    150.              
    151.         'copy the buffer into a FIXED_INFO type
    152.          CopyMemory Info, ByVal VarPtr(buff(0)), LenB(Info)
    153.            
    154.         'and retrieve the host name
    155.          GetHostName = TrimNull(StrConv(Info.hostname, vbUnicode))
    156.      
    157.       End If  'If GetNetworkParams
    158.    End If  'If cbRequired > 0
    159.  
    160. End Function
    161.  
    162. Private Function TrimNull(item As String)
    163.  
    164.     Dim pos As Integer
    165.    
    166.    'double check that there is a chr$(0) in the string
    167.     pos = InStr(item, Chr$(0))
    168.     If pos Then
    169.        TrimNull = Left$(item, pos - 1)
    170.     Else
    171.        TrimNull = item
    172.     End If
    173.  
    174. End Function
    175.  
    176. Private Sub Form_Resize()
    177.  
    178.     On Error Resume Next ' Bypass the error 384. Occurs in Maximized, Minimized or restored mode.
    179.     Me.Height = dex      ' Set the Form Height equal to dex initial in Form_Load()
    180.     Me.Width = dey       ' Set the Form Width equal to dey initial in Form_Load()
    181.  
    182. End Sub
    Last edited by danasegarane; Nov 5th, 2006 at 11:33 PM.

  25. #25

    Thread Starter
    Lively Member FiOh's Avatar
    Join Date
    Sep 2006
    Location
    Another World
    Posts
    104

    Re: Help needed for Project!!

    Quote Originally Posted by danasegarane
    cut & paste these lines
    VB Code:
    1. For Each ctl In Me.Controls
    2.       If TypeOf ctl Is CommandButton Then
    3.          If ctl.Name = "cmdexit" Then
    4.           ctl.Enabled = True   'exit button will be enabled
    5.          Else
    6.              ctl.Enabled = False 'all other command button are disbled
    7.          End If
    8.       End If
    9.        If TypeOf ctl Is ComboBox Then
    10.          ctl.Enabled = False 'all combo boxes are disabled
    11.       End If
    12.      
    13.     Next
    14.     'Check for valid tester

    VB Code:
    1. If InStr(1, Machines, Strhostname) = 0 Then
    2.        MsgBox "Hi" + GetHostName + "U are not running on a valid tester platform."
    3.       'inside this
    4.       'here >>>>>>>>>>>>> Here
    5.     End If
    In which function or Sub should i paste the code in?
    || ~ * FiOh * ~ ||

    Different personality n character... alone,
    difficult to understand n mysterious,
    for I am... Princess Cindistine @ Another World.
    You should know...
    P.C - R.N.A.F. Yeah, that is ME...

  26. #26

    Thread Starter
    Lively Member FiOh's Avatar
    Join Date
    Sep 2006
    Location
    Another World
    Posts
    104

    Re: Help needed for Project!!

    I saw it le.. thanks. Everything is fine now. Just that i cant map to the server, i think it's the problem with the company's pc and network, i will ask my supervisor for that.
    Once again, really thanks for all the troubles.

    *^^*
    || ~ * FiOh * ~ ||

    Different personality n character... alone,
    difficult to understand n mysterious,
    for I am... Princess Cindistine @ Another World.
    You should know...
    P.C - R.N.A.F. Yeah, that is ME...

  27. #27
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: [RESOLVED] Help needed for Project!!

    Part 4
    VB Code:
    1. Private Sub MAP_DRIVE(Driveletter As String, servername As String, customer As String, validtest As String, program1 As String)
    2.     'Function to map the server connetions
    3.     Dim fso As New FileSystemObject
    4.     Dim strPassword As String
    5.     Dim strLocalDriveLetter As String 'New
    6.     Dim strNetworkPathName As String 'New
    7.     Dim MappingRet As Long
    8.     Dim MappinError As String
    9.     txtStatus = txtStatus & vbCrLf & "Starts Mapping..." & vbCrLf & "Processing in progress... Please wait. " & vbCrLf
    10.     Screen.MousePointer = vbHourglass
    11.     strPassword = "flex123"
    12.     strLocalDriveLetter = Driveletter 'assing the drive letter
    13.     strNetworkPathName = "\\" & servername & "\" & customer & program1 & "\" & validtest '& GetHostName
    14.     MappingRet = WNetAddConnection(strNetworkPathName, strPassword, strLocalDriveLetter)
    15.    If MappingRet > 0 Then
    16.      Select Case MappingRet
    17.      Case 53
    18.         MappingError = "The network Path Could not be found"
    19.      Case 65
    20.         MappingError = "The network Path Could not be found"
    21.      Case 54
    22.         MappingError = "The network Path Could not be found"
    23.      Case 86
    24.         MappingError = "The network Path Could not be found"
    25.      Case Else
    26.         MappingError = "An Error occurred mapping the drive." & vbCrLf & "Mapping Failed." & vbCrLf
    27.      End Select
    28.     txtStatus = txtStatus & vbCrLf & "Mapping to " & strNetworkPathName & vbCrLf & MappingError
    29.     Screen.MousePointer = vbDefault
    30. Else
    31.     txtStatus = txtStatus & vbCrLf & "Mapping to " & strNetworkPathName & vbCrLf & "Drive successfully mapped!" & vbCrLf
    32.     Call unmap_drives(False) 'do display all the mapped servers
    33.     Screen.MousePointer = vbDefault
    34.     End If
    35. End Sub
    36.  
    37. Private Function unmap_drives(disconnect As Boolean) As Boolean
    38. On Error GoTo err
    39. Dim Ret As Long
    40. Dim Drive1 As String
    41. Dim WshNetwork
    42. Dim strmain As String
    43. Dim LDs
    44. Dim SDrive1
    45. Dim disconnectit
    46. Dim drives As String
    47. Dim fsodrive As New FileSystemObject
    48.  Dim driveletter1 As String
    49.     LDs = fGetDrives
    50.     Set WshNetwork = CreateObject("WScript.Network")
    51.      SDrive1 = Split(LDs, "\" & vbNullChar) 'get all the drives avaliable
    52.     Dim i As Long
    53.     For i = LBound(SDrive1) To UBound(SDrive1) 'loop though the drives
    54.        If SDrive1(i) <> "" Then
    55.             Drive1 = SDrive1(i)
    56.                 If GetDriveType(Drive1) = 4 Then 'if it is a mapped drive
    57.                         'Where H: is the drive letter you wish to connect
    58.                         'The second parameter of this API determines whether to disconnect the drive if
    59.                         'there are files open on it.   If it is passed FALSE, the disconnect will fail if there are open files
    60.                         'If it is passed TRUE, the disconnect will occur no matter what is open on the drive
    61.                     If disconnect = True Then
    62.                         disconnectit = WNetCancelConnection(Drive1, True) 'disconnect the drive
    63.                     Else
    64.                         drives = Drive1 & fsodrive.GetDrive(Drive1).ShareName 'to display the drives
    65.                         txtStatus.Text = drives & vbCrLf & txtStatus.Text
    66.                     End If
    67.                    
    68.                    
    69.                    
    70.                 End If
    71.           End If
    72.    Next
    73.     Sleep (100)
    74.    unmap_drives = True
    75.     'End If
    76.  
    77. Exit Function
    78. err:
    79.    
    80.     If err.Number <> 0 Then
    81.         If err.Number = -2147024811 Then
    82.             MsgBox "The local device name is already in use.Please Disconnect and Run WMS", vbInformation
    83.             unmap_drives = False
    84.         Else
    85.             MsgBox err.Description, vbInformation
    86.             unmap_drives = False
    87.         End If
    88.     End If
    89. End Function
    90.  
    91. Public Function fGetDrives() As String
    92. 'Returns all mapped drives
    93.     Dim lngRet As Long
    94.     Dim strDrives As String * 255
    95.     Dim lngTmp As Long
    96.     lngTmp = Len(strDrives)
    97.     lngRet = GetLogicalDriveStrings(lngTmp, strDrives)
    98.     fGetDrives = Left(strDrives, lngRet)
    99. End Function
    100. Private Function RunProgram(servername As String, custcode As String, Production As String, Exename As String)
    101.     On Error GoTo Err1
    102.     Dim Exepath As String
    103.     Dim fso As New FileSystemObject
    104.     'Exepath = servername & "\" & custcode & "_" & Production & "\" & Exename
    105.     Exepath = "Y:" & "\" & Exename 'cboProgram.Text
    106.     MsgBox Exepath
    107.     If fso.FileExists(Exepath) Then
    108.       MsgBox Exepath & " :- File Not Found"
    109.     Else
    110.       Shell Exepath, vbNormalFocus
    111.     End If
    112.     'cboMapServer.Text, cboCusCode.Text, validtester, "_Production"
    113. Exit Function
    114. Err1:
    115.      MsgBox err.Description
    116.      Exit Function
    117. End Function
    118.  
    119.  
    120. Private Function ShowMappingError(Mapping_Error_code As Long)
    121.  Dim Buffer As String
    122.     'Create a string buffer
    123.     Buffer = Space(200)
    124.     'Set the error number
    125.    SetLastError Mapping_Error_code
    126.     'Format the message string
    127.     FormatMessage FORMAT_MESSAGE_FROM_SYSTEM, ByVal 0&, GetLastError, LANG_NEUTRAL, Buffer, 200, ByVal 0&
    128.     'Show the message
    129.     MsgBox Buffer
    130.  
    131. End Function
    132. Public Function ExecCmd(cmdline$)
    133.    'Function to run the validataor Exe.
    134.     'This will run the validator exe and wait untill it finishes
    135.    'Shell and Wait Function
    136.     Const STARTF_USESHOWWINDOW As Long = &H1
    137.  
    138.    Dim proc As PROCESS_INFORMATION
    139.    Dim Start As STARTUPINFO
    140.    ' Initialize the STARTUPINFO structure:
    141.    Start.cb = Len(Start)
    142.    'Start.dwFlags = STARTF_USESHOWWINDOW
    143.    Ret& = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, _
    144.       NORMAL_PRIORITY_CLASS, 0&, 0&, Start, proc)
    145.       Ret& = WaitForSingleObject(proc.hProcess, INFINITE)
    146.       Call GetExitCodeProcess(proc.hProcess, Ret&)
    147.       Call CloseHandle(proc.hThread)
    148.       Call CloseHandle(proc.hProcess)
    149.       ExecCmd = Ret&
    150.   '  Call HideProgress
    151. End Function
    152.  
    153. Private Function RunXL_version(version As String)
    154.     Dim arg As String
    155.     Dim XLPath As String
    156.     Dim X As Long
    157.     XLPath = "C:\Program Files\Teradyne\IG-XL\3.40.09\bin"
    158.     arg = XL_VersionExePath & " /V " & version
    159.     ChDrive "c:\"
    160.     X = ExecCmd(arg)
    161. End Function
    Last edited by danasegarane; Nov 5th, 2006 at 11:35 PM.

  28. #28

    Thread Starter
    Lively Member FiOh's Avatar
    Join Date
    Sep 2006
    Location
    Another World
    Posts
    104

    Re: [RESOLVED] Help needed for Project!!

    I have edited the Post #1.
    || ~ * FiOh * ~ ||

    Different personality n character... alone,
    difficult to understand n mysterious,
    for I am... Princess Cindistine @ Another World.
    You should know...
    P.C - R.N.A.F. Yeah, that is ME...

  29. #29
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: [EDITED] Help needed for Project!!

    part 1
    Code:
    'Program Coding
    'Make the Cbo Program style to 2
    'and the same for Custumer code combo
    'This will restrict the user from enterting anything in the combo box
    Option Explicit
    
    '1st 2 lines For No-resize form
    Private dex As Long ' Declare variable dex as Long & Private
    Private dey As Long ' Declare variable dey as Long & Private
    
    Private Const ERROR_SUCCESS         As Long = 0
    Private Const MAX_DOMAIN_NAME_LEN   As Long = 128
    Private Const MAX_HOSTNAME_LEN      As Long = 128
    Private Const MAX_SCOPE_ID_LEN      As Long = 256
    
    Private Type IP_ADDRESS_STRING
        IpAddr(0 To 15)  As Byte
    End Type
    
    Private Type IP_MASK_STRING
        IpMask(0 To 15)  As Byte
    End Type
    
    Private Type IP_ADDR_STRING
        dwNext     As Long
        IpAddress  As IP_ADDRESS_STRING
        IpMask     As IP_MASK_STRING
        dwContext  As Long
    End Type
    
    Private Type FIXED_INFO
      hostname(0 To (MAX_HOSTNAME_LEN + 3))         As Byte
      DomainName(0 To (MAX_DOMAIN_NAME_LEN + 3))    As Byte
      CurrentDnsServer   As IP_ADDR_STRING
      DnsServerList      As IP_ADDR_STRING
      NodeType           As Long
      ScopeId(0 To (MAX_SCOPE_ID_LEN + 3))          As Byte
      EnableRouting      As Long
      EnableProxy        As Long
      EnableDns          As Long
    End Type
    
    Private Declare Function GetNetworkParams Lib "iphlpapi.dll" _
      (pFixedInfo As Any, _
       pOutBufLen As Long) As Long
    
    Private Declare Sub CopyMemory Lib "kernel32" _
       Alias "RtlMoveMemory" _
      (Destination As Any, _
       Source As Any, _
       ByVal Length As Long)
       
    'Declaration for map drive function
    '***********new
    Private Declare Function WNetCancelConnection Lib "mpr.dll" Alias "WNetCancelConnectionA" (ByVal lpszName As String, ByVal bForce As Long) As Long
    Private Declare Function WNetAddConnection2 Lib "mpr.dll" Alias "WNetAddConnection2A" (lpNetResource As NETRESOURCE, ByVal lpPassword As String, ByVal lpUserName As String, ByVal dwFlags As Long) As Long
    'Private Declare Function WNetCancelConnection2 Lib "mpr.dll" Alias "WNetCancelConnection2A" (ByVal lpName As String, ByVal dwFlags As Long, ByVal fForce As Long) As Long
    Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias _
        "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, _
        ByVal lpBuffer As String) As Long
    Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" _
        (ByVal nDrive As String) As Long
    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) 'suspends for process for some time
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Declare Function FormatMessage Lib "kernel32" Alias "FormatMessageA" (ByVal dwFlags As Long, lpSource As Any, ByVal dwMessageId As Long, ByVal dwLanguageId As Long, ByVal lpBuffer As String, ByVal nSize As Long, Arguments As Long) As Long
    Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
       hHandle As Long, ByVal dwMilliseconds As Long) As Long
    
    
    Private Type NETRESOURCE
        dwScope As Long
        dwType As Long
        dwDisplayType As Long
        dwUsage As Long
        pLocalName As String
        pRemoteName As String
        pComment As Long
        pProvider As Long
    End Type
    Private Const RESOURCETYPE_DISK As Long = &H1&
    Dim theNetResource As NETRESOURCE
    '8888888888888888888 new
       
       Private Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000
      
      
        Const WN_SUCCESS = 0 ' The function was successful.
        Const WN_NET_ERROR = 2 ' An error occurred on the network.
        Const WN_BAD_PASSWORD = 6 ' The password was invalid.
    
    'Const Machines = "J750_XX,UFLEX_XX,IFLEX_XX, TSG999_XX" 'To store the valid platform machine numbers.
    Const Machines = "J750-,UFLEX,IFLEX,is-s349a"
    'you can add your machine numbers here
    Const FORMAT_MESSAGE_ALLOCATE_BUFFER = &H100
    Const LANG_NEUTRAL = &H0
    Const SUBLANG_DEFAULT = &H1
    Const ERROR_BAD_USERNAME = 2202&
    Dim custname As String
    Dim validtester As String
    Private Const CB_FINDSTRINGEXACT = &H158 'constant varriable for find the value in the combo box
    
    'New codes
    Private Const ERROR_BAD_NETPATH = 53&
    Private Const ERROR_NETWORK_ACCESS_DENIED = 65&
    Private Const ERROR_INVALID_PASSWORD = 86&
    Private Const ERROR_NETWORK_BUSY = 54&
    Dim StartFlag As Boolean
    'For running the Version exe and wait untill it finishes --start
    Private sMappingservers(4) As String 'For stroring the mapping Server location
    Private sProgramlist(4) As String     'For Stroing the Program List
    
    Private Sub cboProgram_Click()
           On Error GoTo Progerror
        Dim strtext As String
        Dim FindPos As Integer
        strtext = "Please Select a Program Code"
            If Trim(cboProgram.Text) = "Please Select a Program Code" Then
               Exit Sub
            Else
                FindPos = SendMessage(cboProgram.hwnd, CB_FINDSTRINGEXACT, -1, ByVal strtext)
                 If FindPos > -1 Then
                  cboProgram.RemoveItem FindPos
               End If
            End If
    Progerror:
                MsgBox "An Error Occured .Sorry For the Inconvinence" & vbCrLf & err.Description
                Exit Sub
    End Sub
    
    Private Sub cmdExit_Click()
        'For Ending the program
        End
    End Sub
    Private Sub cboCusCode_Click()
        On Error GoTo CustError
        Dim FindPos As Integer
        Dim strtext As String
        'to get the custname
         Dim strposition As Integer ' For finding the postion of program code in program combo
         Dim objCust    'for opening the text file and search for custumer code
         Dim objCust1   'for opening the text file
         Dim strline    'to read the text file as lineby line
         Dim custcode As String 'for storing the custumer code
         Dim programname As String  'for finding the program code in the program combo
         Dim sVersion As String
         Dim i As Integer
         Dim x As Integer
         Dim strcustumernew
         cboProgram.Clear
         custcode = Trim(cbocuscode.Text) & "="   'for stroing the custumer code
         Set objCust = CreateObject("Scripting.FileSystemObject")
         'Real tester path
         
        Set objCust1 = objCust.OpenTextFile("C:\testsys\configfile.txt", 1)
          Do Until objCust1.AtEndOfStream   'loop through the entries in the text file.Read line by line .Untill the end of file is found
             strline = objCust1.ReadLine   'read line  by line
             If InStr(1, strline, custcode, vbTextCompare) > 0 Then  'search for BC1= or CT8= and so on... . if Found then the it will re
             'return a value greater than 0.
                 'After this find cut the line program code only
                 'eg if CT8=ProductionUI or BC1=ProductionUI is found then only cut the part ProductionUI
                 custname = Right(strline, (Len(strline) - InStr(1, strline, "=", vbTextCompare)))
                 'if the return value is like in the format SM4=STMP35XX_FT|STMP35XX_WS|NON_STMP35XX_FT
                  
                  If InStr(1, custname, "|", vbTextCompare) > 0 Then
                    ' then check the postion of | .If | found then split that string with respect to |
                     strcustumernew = Split(custname, "|")
                     If UBound(strcustumernew) > 0 Then
                        For i = 0 To 4
                                sMappingservers(i) = strcustumernew(i)
                        Next
                          x = 0
                        cboProgram.Enabled = True
                        cboProgram.AddItem "Please Select a Program Code", 0
                        For i = 5 To 9
                          If Len(strcustumernew(i)) > 0 Then
                           cboProgram.AddItem strcustumernew(i)
                           x = x + 1
                         End If
                        Next
                      If cboProgram.ListCount > -1 Then
                      '  StartFlag = True
                        cboProgram.ListIndex = 0
                      End If
                    End If
                  End If  'Loop through the array and add the program values in the program combo
                     
             End If
          Loop  'read the next line
         ' cboProgram.ListIndex = 0
        
        strtext = "Please Select a Customer Code"
        If StartFlag = True Then
               Exit Sub
        Else
             
            If Trim(cbocuscode.Text) = "Please Select a Customer Code" Then
               Exit Sub
            Else
                FindPos = SendMessage(cbocuscode.hwnd, CB_FINDSTRINGEXACT, -1, ByVal strtext)
                 If FindPos > -1 Then
                  cbocuscode.RemoveItem FindPos
               End If
            End If
        End If
    Exit Sub
    CustError:
                MsgBox "An Error Occured .Sorry For the Inconvinence" & vbCrLf & err.Description
                Exit Sub
    End Sub
    Last edited by danasegarane; Nov 14th, 2006 at 05:08 AM.

  30. #30
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: [EDITED] Help needed for Project!!

    Part 2
    Code:
    Private Sub cmdOK_Click()
    On Error GoTo okError
    Dim strmsg As String
    Dim strmsg1 As String
    Dim strmsg2 As String
    Dim sPath As String
    Dim sServername As String
    Dim sDriveLetter As String
    Dim x As Integer
     txtStatus.Text = ""
        If Trim(cbocuscode.Text) = "Please Select a Customer Code" Or Trim(cbocuscode.Text) = "" Then
            If Trim(strmsg) <> "" Then
                strmsg = strmsg & vbCrLf & "Customer Code Not Selected"
            Else
                strmsg = "Customer Code Not Selected"
            End If
        End If
        If Trim(cboProgram.Text) = "Please Select a Program Code" Or Trim(cboProgram.Text) = "" Then
           If Trim(strmsg) <> "" Then
                strmsg = strmsg & vbCrLf & "Please Select a Program Code"
            Else
                strmsg = "Please Select a Program Code"
            End If
         End If
        If Trim(strmsg) = "" Then
        Else
        txtStatus.Text = strmsg
        Exit Sub
        End If
        Call unmap_drives(True) 'to disconnect all the server connections
        
        'Function to map drive
            
        Screen.MousePointer = vbHourglass
        For x = 0 To 4
           If Len(sMappingservers(x)) > 0 Then 'if the Mapping server is not empty
                sServername = sMappingservers(x) & "\" & Trim(cboProgram.Text)
                If x = 0 Then
                    'For the First mapping assign the Drive Letter as U
                    sDriveLetter = "U:"
                ElseIf x = 1 Then
                    sDriveLetter = "W:" 'second mapping as "W:"
                ElseIf x = 2 Then
                    sDriveLetter = "X:"  'Third mapping as "X"
                ElseIf x = 3 Then
                    sDriveLetter = "Y:" 'Fouth mapping as "Y:"
                ElseIf x = 4 Then       'Fifth Mapping as "Z"
                    sDriveLetter = "Z:"
                End If
                'attempt to map the drive
                Call MAP_DRIVE(sDriveLetter, sServername)
          End If
        Next
         
        Screen.MousePointer = vbDefault
        
        'Disable the OK btn after mapping
        cmdok.Enabled = False
        'frmNPL.WindowState = vbMinimized
    Exit Sub
    okError:
               MsgBox "An Error Occured .Sorry For the Inconvinence" & vbCrLf & err.Description
                Exit Sub
    End Sub
    Private Sub Form_Load()
               On Error GoTo FormLoadError
                Dim Strhostname As String
                Dim objFSO
                Dim objFile
                Set objFSO = CreateObject("Scripting.FileSystemObject")
                Dim strline
                Dim mappingserver
                Dim cust_code As String
                Dim customercodes
                Dim i As Integer
                StartFlag = True
                lblPCName = GetHostName()
                txtStatus.Text = ""
                'Check for valid tester
                cboProgram.Enabled = False
                 Strhostname = GetHostName
                 validtester = Left(Strhostname, 5) 'assin the valid testername
                    If InStr(1, Machines, validtester) = 0 Then
                    MsgBox "Hi " + GetHostName + ", this is not a valid tester/platform." & vbCrLf & "Therefore you are not allow to map to our server!!!" & vbCrLf & "Any issue, pls get back to Test System Group." & vbCrLf & "Thanks.", 64, "Invalid Tester Platform"
                        ' if he is not a valid user .The combo box will be disable
                        ' if you wan to hide the combo box you can change this coding to " --->>>> cboprogram.visible=False
                        cboProgram.Enabled = False
                        cbocuscode.Enabled = False 'disables the custcode combo
                        cbomapserver.Enabled = False 'disables the cbomapserver
                        cmdok.Enabled = False       'disables the cmdok combo
                            'cmdExit.Enabled = False 'disables the cmdexit combo
                            'Exit Sub 'exit the below coding.if you want you can comment this line
                    End If
               
                dex = Me.Height ' Set dex equal to Form Height
                dey = Me.Width  ' Set dey equal to Form Width
                
                'Center the form on screen
                Me.Move (Screen.Width - Me.Width) \ 2, (Screen.Height - Me.Height) \ 2
                
                 
                 Dim fso1 As New FileSystemObject
                 If fso1.FileExists("C:\testsys\configfile.txt") = False Then
                 'If fso1.FileExists("C:\Documents and Settings\IA1\My Documents\configfile.txt") = False Then
                 
                     cboProgram.Enabled = False
                     cbocuscode.Enabled = False 'disables the custcode combo
                     cbomapserver.Enabled = False 'disables the cbomapserver
                     cmdok.Enabled = False
                     Exit Sub
                    Else
                 Set objFile = objFSO.OpenTextFile("C:\testsys\configfile.txt", 1)
                 'Set objFile = objFSO.OpenTextFile("C:\Documents and Settings\IA1\My Documents\configfile.txt", 1)
                 End If
            
                    Do Until objFile.AtEndOfStream 'read untill end of file is found
                        strline = objFile.ReadLine 'read the line
                        '1.......this part will add the servername code in the combox -start
                        'SEARCH for string  "MappingServer="
                        
                        
                        'this part will add the custmer code in the combox -start
                        If InStr(1, strline, "CustomerCode=", vbTextCompare) > 0 Then 'read the custname name line
                            cbocuscode.AddItem "Please Select a Customer Code"
                            cboProgram.AddItem "Please Select a Program Code"
                            'search for the string "customerocode="
                            cust_code = Right(strline, (Len(strline) - InStr(1, strline, "=", vbTextCompare)))
                            If InStr(1, cust_code, "|", vbTextCompare) > 0 Then
                                'and split the strline varriable with respect to |
                                customercodes = Split(cust_code, "|")
                                    For i = LBound(customercodes) To UBound(customercodes)
                                        cbocuscode.AddItem customercodes(i) 'add the custumer codes in the combo
                                    Next
                            End If
                        End If
                        ''this part will add the custmer code in the combox -End
                    Loop 'read the next line
                    If cbocuscode.ListCount > -1 Then cbocuscode.ListIndex = 0
                Call unmap_drives(False) 'to display the all the mapped servers in the status list
                StartFlag = False
    Exit Sub
    
    FormLoadError:
                    MsgBox "An Error Occured .Sorry For the Inconvinence" & vbCrLf & err.Description
                    Exit Sub
                       
    End Sub
    Last edited by danasegarane; Nov 14th, 2006 at 05:09 AM. Reason: code changed

  31. #31
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: [EDITED] Help needed for Project!!

    Part 3
    Code:
    Public Function GetHostName() As String
    'Function to get the host name
       Dim buff()        As Byte
       Dim cbRequired    As Long
       Dim nStructSize   As Long
       Dim Info          As FIXED_INFO
    
      'Call the api passing null as pFixedInfo.
      'The required size of the buffer for the
      'data is returned in cbRequired
       Call GetNetworkParams(ByVal 0&, cbRequired)
    
       If cbRequired > 0 Then
        
         'create a buffer of the needed size
          ReDim buff(0 To cbRequired - 1) As Byte
          
         'and call again
          If GetNetworkParams(buff(0), cbRequired) = ERROR_SUCCESS Then
                  
            'copy the buffer into a FIXED_INFO type
             CopyMemory Info, ByVal VarPtr(buff(0)), LenB(Info)
                
            'and retrieve the host name
             GetHostName = TrimNull(StrConv(Info.hostname, vbUnicode))
          
          End If  'If GetNetworkParams
       End If  'If cbRequired > 0
    
    End Function
    
    Private Function TrimNull(item As String)
        Dim pos As Integer
       'double check that there is a chr$(0) in the string
        pos = InStr(item, Chr$(0))
        If pos Then
           TrimNull = Left$(item, pos - 1)
        Else
           TrimNull = item
        End If
    End Function
    Private Sub Form_Resize()
        On Error Resume Next ' Bypass the error 384. Occurs in Maximized, Minimized or restored mode.
        Me.Height = dex      ' Set the Form Height equal to dex initial in Form_Load()
        Me.Width = dey       ' Set the Form Width equal to dey initial in Form_Load()
    End Sub
    
    Private Sub MAP_DRIVE(Driveletter As String, servername As String)
        On Error GoTo MappingError
        
        'Function to map the server connetions
        Dim fso As New FileSystemObject
        Dim strPassword As String
        Dim strusername As String
        Dim strLocalDriveLetter As String 'New
        Dim strNetworkPathName As String 'New
        Dim MappingRet As Long
        Dim MappingError As String
        txtStatus = txtStatus & vbCrLf & "Starts Mapping..." & vbCrLf & "Processing in progress... Please wait. " & vbCrLf
        Screen.MousePointer = vbHourglass
        strPassword = "flex123"
        strusername = "test"
        theNetResource.pRemoteName = servername
        theNetResource.pLocalName = Driveletter
         theNetResource.dwType = RESOURCETYPE_DISK
        MappingRet = WNetAddConnection2(theNetResource, strPassword, strusername, 0)
       If MappingRet > 0 Then
         Select Case MappingRet
         Case 53
            'IF the return values is 53 , then the network path is not found
            MappingError = "The network Path Could not be found"
         Case 65
            'IF the return values is 65 , then user doesnot have the access to the network path
            MappingError = "The Network Access Denied"
         Case 54
            'IF the return values is 54 , then the network is busy
            MappingError = "The Network is Busy.. Try after Some time"
         Case 86
            'IF the return values is 86 , then the networ path is invaid
            MappingError = "The network Path is Invalid"
         Case Else
            MappingError = APIErrorDescription(MappingRet)
            MappingError = MappingError & vbCrLf & "An Error occurred mapping the drive." & vbCrLf & "Mapping Failed." & vbCrLf
         End Select
        txtStatus = txtStatus & vbCrLf & "Mapping to " & strNetworkPathName & vbCrLf & MappingError
        Screen.MousePointer = vbDefault
    Else
        'Newly added
        'This will check wheather the particular drive exist or not.If mapped successfully it will goto the next step
        If fso.DriveExists(Driveletter) = True Then
          'If the drive is there  then it will get the name
          'and compare the name with the name that is to  be mapped(strnetworkname)
          'if It matches it wll display the message,as sucess
          If fso.GetDrive(Driveletter).ShareName = strNetworkPathName Then
            txtStatus = txtStatus & vbCrLf & "Mapping to " & strNetworkPathName & vbCrLf & "Drive successfully mapped!" & vbCrLf
            Call unmap_drives(False) 'do display all the mapped servers
            Screen.MousePointer = vbDefault
          End If
       Else
          'else Error messsgage
           MappingError = "An Error occurred mapping the drive." & vbCrLf & "Mapping Failed." & vbCrLf
           txtStatus = txtStatus & vbCrLf & "Mapping to " & strNetworkPathName & vbCrLf & MappingError
       End If
    End If
    Exit Sub
    MappingError:
                MsgBox "An Error Occured .Sorry For the Inconvinence" & vbCrLf & err.Description
                Exit Sub
    End Sub
    
    Private Function unmap_drives(disconnect As Boolean) As Boolean
    On Error GoTo err
    Dim ret As Long
    Dim Drive1 As String
    Dim WshNetwork
    Dim strmain As String
    Dim LDs
    Dim SDrive1
    Dim disconnectit
    Dim drives As String
    Dim fsodrive As New FileSystemObject
     Dim driveletter1 As String
        LDs = fGetDrives
        Set WshNetwork = CreateObject("WScript.Network")
         SDrive1 = Split(LDs, "\" & vbNullChar) 'get all the drives avaliable
        Dim i As Long
        For i = LBound(SDrive1) To UBound(SDrive1) 'loop though the drives
           If SDrive1(i) <> "" Then
                Drive1 = SDrive1(i)
                    If GetDriveType(Drive1) = 4 Then 'if it is a mapped drive
                            'Where H: is the drive letter you wish to connect
                            'The second parameter of this API determines whether to disconnect the drive if
                            'there are files open on it.   If it is passed FALSE, the disconnect will fail if there are open files
                            'If it is passed TRUE, the disconnect will occur no matter what is open on the drive
                        If disconnect = True Then
                            disconnectit = WNetCancelConnection(Drive1, True) 'disconnect the drive
                        Else
                            drives = Drive1 & fsodrive.GetDrive(Drive1).ShareName 'to display the drives
                            txtStatus.Text = drives & vbCrLf & txtStatus.Text
                        End If
                        
                        
                        
                    End If
              End If
       Next
        Sleep (100)
       unmap_drives = True
        'End If
    
    Exit Function
    err:
        
        If err.Number <> 0 Then
            If err.Number = -2147024811 Then
                MsgBox "The local device name is already in use.Please Disconnect and Run WMS", vbInformation
                unmap_drives = False
            Else
                MsgBox err.Description, vbInformation
                unmap_drives = False
            End If
        End If
    End Function
    
    Public Function fGetDrives() As String
    'Returns all mapped drives
        Dim lngRet As Long
        Dim strDrives As String * 255
        Dim lngTmp As Long
        lngTmp = Len(strDrives)
        lngRet = GetLogicalDriveStrings(lngTmp, strDrives)
        fGetDrives = Left(strDrives, lngRet)
    End Function
    
    Public Function APIErrorDescription(ErrorCode As Long) As String
    Dim sAns As String
    Dim lRet As Long
    
    'PURPOSE: Returns Human Readable Description of
    'Error Code that occurs in API function
    
    'PARAMETERS: ErrorCode: System Error Code
    
    'Returns: Description of Error
    
    'Example: After Calling API Function:
             'MsgBox (APIErrorDescription(Err.LastDllError))
     
    sAns = Space(255)
    lRet = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, _
       ErrorCode, 0, sAns, 255, 0)
    
    APIErrorDescription = StripNull(sAns)
    
    End Function
    
    Private Function StripNull(ByVal InString As String) As String
    
    'Input: String containing null terminator (Chr(0))
    'Returns: all character before the null terminator
    
    Dim iNull As Integer
    If Len(InString) > 0 Then
        iNull = InStr(InString, vbNullChar)
        Select Case iNull
        Case 0
            StripNull = Trim(InString)
        Case 1
            StripNull = ""
        Case Else
           StripNull = Left$(Trim(InString), iNull - 1)
       End Select
    End If
    
    End Function
    Last edited by danasegarane; Nov 14th, 2006 at 05:10 AM.

  32. #32

    Thread Starter
    Lively Member FiOh's Avatar
    Join Date
    Sep 2006
    Location
    Another World
    Posts
    104

    Re: [EDITED] Help needed for Project!!

    Thank you soo much!!
    *^^*
    || ~ * FiOh * ~ ||

    Different personality n character... alone,
    difficult to understand n mysterious,
    for I am... Princess Cindistine @ Another World.
    You should know...
    P.C - R.N.A.F. Yeah, that is ME...

  33. #33
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: [RESOLVED] [EDITED] Help needed for Project!!

    Dear Fioh,
    Replace this module in your program.
    VB Code:
    1. Option Explicit
    2.  
    3. '1st 2 lines For No-resize form
    4. Private dex As Long ' Declare variable dex as Long & Private
    5. Private dey As Long ' Declare variable dey as Long & Private
    6.  
    7. Private Const ERROR_SUCCESS         As Long = 0
    8. Private Const MAX_DOMAIN_NAME_LEN   As Long = 128
    9. Private Const MAX_HOSTNAME_LEN      As Long = 128
    10. Private Const MAX_SCOPE_ID_LEN      As Long = 256
    11.  
    12. Private Type IP_ADDRESS_STRING
    13.     IpAddr(0 To 15)  As Byte
    14. End Type
    15.  
    16. Private Type IP_MASK_STRING
    17.     IpMask(0 To 15)  As Byte
    18. End Type
    19.  
    20. Private Type IP_ADDR_STRING
    21.     dwNext     As Long
    22.     IpAddress  As IP_ADDRESS_STRING
    23.     IpMask     As IP_MASK_STRING
    24.     dwContext  As Long
    25. End Type
    26.  
    27. Private Type FIXED_INFO
    28.   hostname(0 To (MAX_HOSTNAME_LEN + 3))         As Byte
    29.   DomainName(0 To (MAX_DOMAIN_NAME_LEN + 3))    As Byte
    30.   CurrentDnsServer   As IP_ADDR_STRING
    31.   DnsServerList      As IP_ADDR_STRING
    32.   NodeType           As Long
    33.   ScopeId(0 To (MAX_SCOPE_ID_LEN + 3))          As Byte
    34.   EnableRouting      As Long
    35.   EnableProxy        As Long
    36.   EnableDns          As Long
    37. End Type
    38.  
    39. Private Declare Function GetNetworkParams Lib "iphlpapi.dll" _
    40.   (pFixedInfo As Any, _
    41.    pOutBufLen As Long) As Long
    42.  
    43. Private Declare Sub CopyMemory Lib "kernel32" _
    44.    Alias "RtlMoveMemory" _
    45.   (Destination As Any, _
    46.    Source As Any, _
    47.    ByVal Length As Long)
    48.    
    49. 'Declaration for map drive function
    50. Private Declare Function WNetAddConnection Lib "mpr.dll" Alias "WNetAddConnectionA" (ByVal lpszNetPath As String, ByVal lpszPassword As String, ByVal lpszLocalName As String) As Long
    51.     Const WN_SUCCESS = 0 ' The function was successful.
    52.     Const WN_NET_ERROR = 2 ' An error occurred on the network.
    53.     Const WN_BAD_PASSWORD = 6 ' The password was invalid.
    54. Private Declare Function WNetCancelConnection Lib "mpr.dll" Alias "WNetCancelConnectionA" (ByVal lpszName As String, ByVal bForce As Long) As Long
    55. Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias _
    56.     "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, _
    57.     ByVal lpBuffer As String) As Long
    58. Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" _
    59.     (ByVal nDrive As String) As Long
    60. Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) 'suspends for process for some time
    61. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    62. Const Machines = "J750_XX,UFLEX_XX,IFLEX_XX" 'To store the valid platform machine numbers.
    63. 'you can add your machine numbers here
    64. Dim custname As String
    65. Dim validtester As String
    66. Private Const CB_FINDSTRINGEXACT = &H158 'constant varriable for find the value in the combo box
    67. Dim StartFlag As Boolean
    68.  
    69. Private Sub cboMapServer_Click()
    70.     Dim Findpos As Integer
    71.     Dim strtext As String
    72.     strtext = "Please Select a Server to Map"
    73.     If StartFlag = True Then
    74.         Exit Sub
    75.     Else
    76.         If Trim(cboMapServer.Text) = "Please Select a Server to Map" Then
    77.            Exit Sub
    78.         Else
    79.            Findpos = SendMessage(cboMapServer.hwnd, CB_FINDSTRINGEXACT, -1, ByVal strtext)
    80.            If Findpos > -1 Then
    81.               cboMapServer.RemoveItem Findpos
    82.            End If
    83.         End If
    84.     End If
    85. End Sub
    86.  
    87. Private Sub cboprogram_Click()
    88.     Dim Findpos As Integer
    89.     Dim strtext As String
    90.     strtext = "Please Select a Program to Launch"
    91.     If StartFlag = True Then
    92.         Exit Sub
    93.     Else
    94.         If Trim(cboprogram.Text) = "Please Select a Program to Launch" Then
    95.             Exit Sub
    96.         Else
    97.               Findpos = SendMessage(cboprogram.hwnd, CB_FINDSTRINGEXACT, -1, ByVal strtext)
    98.              If Findpos > -1 Then
    99.               cboprogram.RemoveItem Findpos
    100.            End If
    101.         End If
    102.     End If
    103. End Sub
    104.  
    105. Private Sub cmdExit_Click()
    106.     'For Ending the program
    107.     End
    108. End Sub
    Last edited by danasegarane; Oct 9th, 2006 at 11:36 AM.

  34. #34
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: [RESOLVED] [EDITED] Help needed for Project!!

    VB Code:
    1. Private Sub cboCusCode_Click()
    2.     Dim Findpos As Integer
    3.     Dim strtext As String
    4.     'to get the custname
    5.      Dim strposition As Integer ' For finding the postion of program code in program combo
    6.      Dim objCust    'for opening the text file and search for custumer code
    7.      Dim objCust1   'for opening the text file
    8.      Dim strline    'to read the text file as lineby line
    9.      Dim custcode As String 'for storing the custumer code
    10.      Dim programname As String  'for finding the program code in the program combo
    11.      Dim i As Integer
    12.      Dim strcustumernew
    13.      custcode = Trim(cboCusCode.Text) & "="   'for stroing the custumer code
    14.      Set objCust = CreateObject("Scripting.FileSystemObject")
    15. '     Set objCust1 = objCust.OpenTextFile("C:\Documents and Settings\IA1\My Documents\configfile.txt", 1)
    16.       Set objCust1 = objCust.OpenTextFile("C:\configfile.txt", 1) 'open text file for reading
    17.       cboprogram.Clear  'clear the cboprogram Entries
    18.         cboprogram.AddItem "Please Select a Program to Launch"
    19.       Do Until objCust1.AtEndOfStream   'loop through the entries in the text file.Read line by line .Untill the end of file is found
    20.          strline = objCust1.ReadLine   'read line  by line
    21.          If InStr(1, strline, custcode, vbTextCompare) > 0 Then  'search for BC1= or CT8= and so on... . if Found then the it will re
    22.          'return a value greater than 0.
    23.              'After this find cut the line program code only
    24.              'eg if CT8=ProductionUI or BC1=ProductionUI is found then only cut the part ProductionUI
    25.              custname = Right(strline, (Len(strline) - InStr(1, strline, "=", vbTextCompare)))
    26.              'if the return value is like in the format SM4=STMP35XX_FT|STMP35XX_WS|NON_STMP35XX_FT
    27.               If InStr(1, custname, "|", vbTextCompare) > 0 Then
    28.                 ' then check the postion of | .If | found then split that string with respect to |
    29.                  strcustumernew = Split(custname, "|")
    30.                 'Loop through the array and add the program values in the program combo
    31.                  For i = LBound(strcustumernew) To UBound(strcustumernew)
    32.                    programname = strcustumernew(i) 'assign the program code in the varriable
    33.                    'search code the code in the program combo.
    34.                     'if found then "strpostion" will be greater than 0 and the retrun the location of the
    35.                     'value in the program combo as either 0 or 1 or so on
    36.                    strposition = SendMessage(cboprogram.hwnd, CB_FINDSTRINGEXACT, -1, ByVal programname)
    37.                    'if not found, then the return value wiil be -1 .Then add the value in the program combo
    38.                    If strposition = -1 Then
    39.                        cboprogram.AddItem strcustumernew(i)
    40.                    End If
    41.                  Next
    42.              Else  'same if it is like CT8=ProductionUI or BC1=ProductionUI
    43.              ' add the program code in the program combo
    44.                 strposition = SendMessage(cboprogram.hwnd, CB_FINDSTRINGEXACT, -1, ByVal custname)
    45.                 If strposition = -1 Then
    46.                 cboprogram.AddItem custname
    47.                 End If
    48.              End If
    49.          End If
    50.       Loop  'read the next line
    51.       cboprogram.ListIndex = 0
    52.    
    53.     strtext = "Please Select a Customer Code"
    54.     If StartFlag = True Then
    55.            Exit Sub
    56.     Else
    57.          
    58.         If Trim(cboCusCode.Text) = "Please Select a Customer Code" Then
    59.            Exit Sub
    60.         Else
    61.             Findpos = SendMessage(cboCusCode.hwnd, CB_FINDSTRINGEXACT, -1, ByVal strtext)
    62.              If Findpos > -1 Then
    63.               cboCusCode.RemoveItem Findpos
    64.            End If
    65.         End If
    66.     End If
    67. End Sub
    68.  
    69. Private Sub cmdOK_Click()
    70. Dim strmsg As String
    71. Dim strmsg1 As String
    72. Dim strmsg2 As String
    73.  txtstatus.Text = ""
    74.  
    75.     If Trim(cboMapServer.Text) = "Please Select a Server to Map" Then
    76.         strmsg = "Mapping Server Not selected"
    77.     End If
    78.  
    79.     If Trim(cboCusCode.Text) = "Please Select a Customer Code" Then
    80.         If Trim(strmsg) <> "" Then
    81.             strmsg = strmsg & vbCrLf & "Customer Code Not Selected"
    82.         Else
    83.             strmsg = "Customer Code Not Selected"
    84.         End If
    85.     End If
    86.     If Trim(cboprogram.Text) = "Please Select a Program to Launch" Then
    87.         If Trim(strmsg) <> "" Then
    88.             strmsg = strmsg & vbCrLf & "Program to Launch Not selected"
    89.         Else
    90.             strmsg = "Program to Launch Not selected"
    91.         End If
    92.     End If
    93.     If Trim(strmsg) = "" Then
    94.    
    95.     Else
    96.     txtstatus.Text = strmsg
    97.     Exit Sub
    98.     End If
    99.     Call unmap_drives(True) 'to disconnect all the server connections
    100.    
    101.     'Function to map drive
    102.     'servername format should be in the format "\\nettapp"
    103.    ' Driveletter = cboDeviceType & ":" 'assing the drive letter
    104.     'Call MAP_DRIVE("W:", cboMapServer.Text, cboCusCode.Text, validtester, "_Engineering") '\\Server\CustomerCode_Engineering\ValidTester\Program
    105.     'Call MAP_DRIVE("X:", cboMapServer.Text, custname, validtester, cboProgram.Text, "_Datalog") '\\Server\CustomerCode_Datalog\ValidTester\Program
    106.     Call MAP_DRIVE("Y:", cboMapServer.Text, cboCusCode.Text, validtester, "_Production") '\\Server\CustomerCode_Production\ValidTester\Program
    107.     Dim wpath As String
    108.     wpath = "" '-->>>fill your requirements
    109.     If WNetAddConnection(Strpath, strPassword, strLocalDriveLetter) > 0 Then 'Enter Path in Strpath and Password in Strpassword and Driveletter
    110.         MsgBox "An Error occurred mapping the drive", 16, "Error Message"
    111.         'End
    112.         Screen.MousePointer = vbDefault
    113.     Else
    114.         MsgBox txtstatus.Text & ": Drive successfully mapped!", 64, "Information"
    115.         Screen.MousePointer = vbDefault
    116.     End If
    117.     'This Function will Run the Correcponing exe
    118.     Call RunProgram(Trim(cboMapServer.Text), Trim(cboCusCode.Text), "_production", "production.exe")
    119.    
    120.        
    121. End Sub
    Last edited by danasegarane; Oct 9th, 2006 at 11:38 AM.

  35. #35
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: [RESOLVED] [EDITED] Help needed for Project!!

    VB Code:
    1. Private Sub Form_Load()
    2.             Dim Strhostname As String
    3.             Dim objFSO
    4.             Dim objFile
    5.             Set objFSO = CreateObject("Scripting.FileSystemObject")
    6.             Dim strline
    7.             Dim mappingserver
    8.             Dim cust_code As String
    9.             Dim customercodes
    10.             Dim i As Integer
    11.             StartFlag = True
    12.             lblPCName = GetHostName()
    13.             txtstatus.Text = ""
    14.             'Check for valid tester
    15.             Strhostname = GetHostName
    16.                 If InStr(1, Machines, Strhostname) = 0 Then
    17.                     MsgBox "Hi " + GetHostName + ", this is not a valid tester/platform." & vbCrLf & "Therefore you are not allow to map to our server!!!" & vbCrLf & "Any issue, pls get back to Test System Group." & vbCrLf & "Thanks. ^-^", 64, "Invalid Tester Platform"
    18.                     ' if he is not a valid user .The combo box will be disable
    19.                     ' if you wan to hide the combo box you can change this coding to " --->>>> cboprogram.visible=False
    20.                     cboprogram.Enabled = False 'disables the program combo
    21.                     lblprogram.Visible = False 'hide the lblprogram
    22.                     cboprogram.Visible = False 'hide the cboprogram combo
    23.                     cboCusCode.Enabled = False 'disables the custcode combo
    24.                     cboMapServer.Enabled = False 'disables the cbomapserver
    25.                     cmdok.Enabled = False       'disables the cmdok combo
    26.                     cmdexit.Enabled = False 'disables the cmdexit combo
    27.                     'Exit Sub 'exit the below coding.if you want you can comment this line
    28.                 End If
    29.             validtester = Left(Strhostname, 4) 'assin the valid testername
    30.             dex = Me.Height ' Set dex equal to Form Height
    31.             dey = Me.Width  ' Set dey equal to Form Width
    32.            
    33.             'Center the form on screen
    34.             Me.Move (Screen.Width - Me.Width) \ 2, (Screen.Height - Me.Height) \ 2
    35.            
    36.             'To display the PC Name
    37.             'open the text file for reading.
    38.             ' Set objFile = objFSO.OpenTextFile("C:\Documents and Settings\IA1\My Documents\configfile.txt", 1)
    39.             Set objFile = objFSO.OpenTextFile("C:\configfile.txt", 1)
    40.                 Do Until objFile.AtEndOfStream 'read untill end of file is found
    41.                     strline = objFile.ReadLine 'read the line
    42.                     '1.......this part will add the servername code in the combox -start
    43.                     'SEARCH for string  "MappingServer="
    44.                    
    45.                     If InStr(1, strline, "MappingServer=", vbTextCompare) > 0 Then 'search for the word = , in the line
    46.                     'if found
    47.                         Dim strservers
    48.                         Dim strserver
    49.                         Dim servername As String
    50.                         Dim x
    51.                         'if found then find the return the postion of =
    52.                         'assing the value of mapping sever in the varriable
    53.                         cboMapServer.AddItem "Please Select a Server to Map"
    54.                         mappingserver = Right(strline, (Len(strline) - InStr(1, strline, "=", vbTextCompare))) 'adds the servername in the combo box
    55.                         'search for string |
    56.                         ' if found
    57.                         If InStr(1, mappingserver, "|", vbTextCompare) > 0 Then
    58.                             'spilit the string with respect to |
    59.                             strservers = Split(mappingserver, "|")
    60.                                 'loop through the array
    61.                                 For x = LBound(strservers) To UBound(strservers)
    62.                                     servername = strservers(x)
    63.                                     'find the servername in the cbo sever combo
    64.                                     strserver = SendMessage(cboMapServer.hwnd, CB_FINDSTRINGEXACT, -1, ByVal servername)
    65.                                     'if not found, then the return value wiil be -1 .Then add the value in the program combo
    66.                                         'if not not found then add the server name
    67.                                         If strserver = -1 Then
    68.                                             cboMapServer.AddItem strservers(x)
    69.                                         End If
    70.                                 Next
    71.                             Else
    72.                             '' if not found the | .Then only only one server and add that server
    73.                             servername = mappingserver
    74.                             strserver = SendMessage(cboMapServer.hwnd, CB_FINDSTRINGEXACT, -1, ByVal servername)
    75.                             'if not found, then the return value wiil be -1 .Then add the value in the program combo
    76.                                 If strserver = -1 Then
    77.                                    cboMapServer.AddItem servername
    78.                                 End If
    79.                         End If
    80.                     End If
    81.                    
    82.                     'this part will add the custmer code in the combox -start
    83.                     If InStr(1, strline, "CustomerCode=", vbTextCompare) > 0 Then 'read the custname name line
    84.                         cboCusCode.AddItem "Please Select a Customer Code"
    85.                         'search for the string "customerocode="
    86.                         cust_code = Right(strline, (Len(strline) - InStr(1, strline, "=", vbTextCompare)))
    87.                         'if the "customerocode=" string found in the strline varriable, then found the postion of |
    88.                         ' in string "CustomerCode=BC1|CT8|TW3|SM4|SY1|XM1|AK1|SN2|SE2|SM1"
    89.                         'cut the custumer codes only as "BC1|CT8|TW3|SM4|SY1|XM1|AK1|SN2|SE2|SM1"
    90.                         If InStr(1, cust_code, "|", vbTextCompare) > 0 Then
    91.                             'and split the strline varriable with respect to |
    92.                             customercodes = Split(cust_code, "|")
    93.                                 For i = LBound(customercodes) To UBound(customercodes)
    94.                                     cboCusCode.AddItem customercodes(i) 'add the custumer codes in the combo
    95.                                 Next
    96.                         End If
    97.                     End If
    98.                     ''this part will add the custmer code in the combox -End
    99.                 Loop 'read the next line
    100.            
    101.             Call unmap_drives(False) 'to display the all the mapped servers in the status list
    102.             cboMapServer.ListIndex = 0
    103.             cboCusCode.ListIndex = 0
    104.             StartFlag = False
    105.  
    106. End Sub
    107.  
    108. Public Function GetHostName() As String
    109. 'Function to get the host name
    110.    Dim buff()        As Byte
    111.    Dim cbRequired    As Long
    112.    Dim nStructSize   As Long
    113.    Dim Info          As FIXED_INFO
    114.  
    115.   'Call the api passing null as pFixedInfo.
    116.   'The required size of the buffer for the
    117.   'data is returned in cbRequired
    118.    Call GetNetworkParams(ByVal 0&, cbRequired)
    119.  
    120.    If cbRequired > 0 Then
    121.    
    122.      'create a buffer of the needed size
    123.       ReDim buff(0 To cbRequired - 1) As Byte
    124.      
    125.      'and call again
    126.       If GetNetworkParams(buff(0), cbRequired) = ERROR_SUCCESS Then
    127.              
    128.         'copy the buffer into a FIXED_INFO type
    129.          CopyMemory Info, ByVal VarPtr(buff(0)), LenB(Info)
    130.            
    131.         'and retrieve the host name
    132.          GetHostName = TrimNull(StrConv(Info.hostname, vbUnicode))
    133.      
    134.       End If  'If GetNetworkParams
    135.    End If  'If cbRequired > 0
    136.  
    137. End Function
    138.  
    139. Private Function TrimNull(item As String)
    140.  
    141.     Dim pos As Integer
    142.    
    143.    'double check that there is a chr$(0) in the string
    144.     pos = InStr(item, Chr$(0))
    145.     If pos Then
    146.        TrimNull = Left$(item, pos - 1)
    147.     Else
    148.        TrimNull = item
    149.     End If
    150.  
    151. End Function
    152.  
    153. Private Sub Form_Resize()
    154.  
    155.     On Error Resume Next ' Bypass the error 384. Occurs in Maximized, Minimized or restored mode.
    156.     Me.Height = dex      ' Set the Form Height equal to dex initial in Form_Load()
    157.     Me.Width = dey       ' Set the Form Width equal to dey initial in Form_Load()
    158.  
    159. End Sub
    160.  
    161.  
    162. Private Sub MAP_DRIVE(Driveletter As String, servername As String, customer As String, validtest As String, program1 As String)
    163.     'Function to map the server connetions
    164.     Dim fso As New FileSystemObject
    165.     Dim strPassword As String
    166.     Dim strLocalDriveLetter As String 'New
    167.     Dim strNetworkPathName As String 'New
    168.    
    169.     txtstatus = "Mapping in Process..."
    170.     Screen.MousePointer = vbHourglass
    171.     strPassword = "flex123"
    172.     strLocalDriveLetter = Driveletter 'assing the drive letter
    173.     strNetworkPathName = "\\" & servername & "\" & customer & program1 & "\UFLEX"  '& validtest
    174.     MsgBox strNetworkPathName 'show server path
    175.     MsgBox strLocalDriveLetter
    176.    
    177. If WNetAddConnection(strNetworkPathName, strPassword, strLocalDriveLetter) > 0 Then
    178.     MsgBox "An Error occurred mapping the drive", 16, "Error Message"
    179.     'End
    180.     txtstatus = "Mapping Failed."
    181.     Screen.MousePointer = vbDefault
    182. Else
    183.     MsgBox txtstatus.Text & ": Drive successfully mapped!", 64, "Information"
    184.     Call unmap_drives(False) 'do display all the mapped servers
    185.     Screen.MousePointer = vbDefault
    186.     End If
    187. End Sub
    Last edited by danasegarane; Oct 9th, 2006 at 11:41 AM.

  36. #36
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: [RESOLVED] [EDITED] Help needed for Project!!

    VB Code:
    1. Private Function unmap_drives(disconnect As Boolean) As Boolean
    2. On Error GoTo err
    3. Dim Ret As Long
    4. Dim Drive1 As String
    5. Dim WshNetwork
    6. Dim strmain As String
    7. Dim LDs
    8. Dim SDrive1
    9. Dim disconnectit
    10. Dim drives As String
    11. Dim fsodrive As New FileSystemObject
    12.  Dim driveletter1 As String
    13.     LDs = fGetDrives
    14.     Set WshNetwork = CreateObject("WScript.Network")
    15.      SDrive1 = Split(LDs, "\" & vbNullChar) 'get all the drives avaliable
    16.     Dim i As Long
    17.     For i = LBound(SDrive1) To UBound(SDrive1) 'loop though the drives
    18.        If SDrive1(i) <> "" Then
    19.             Drive1 = SDrive1(i)
    20.                 If GetDriveType(Drive1) = 4 Then 'if it is a mapped drive
    21.                         'Where H: is the drive letter you wish to connect
    22.                         'The second parameter of this API determines whether to disconnect the drive if
    23.                         'there are files open on it.   If it is passed FALSE, the disconnect will fail if there are open files
    24.                         'If it is passed TRUE, the disconnect will occur no matter what is open on the drive
    25.                     If disconnect = True Then
    26.                         disconnectit = WNetCancelConnection(Drive1, True) 'disconnect the drive
    27.                     Else
    28.                         drives = Drive1 & fsodrive.GetDrive(Drive1).ShareName 'to display the drives
    29.                         txtstatus.Text = drives & vbCrLf & txtstatus.Text
    30.                     End If
    31.                    
    32.                    
    33.                    
    34.                 End If
    35.           End If
    36.    Next
    37.     Sleep (100)
    38.    unmap_drives = True
    39.     'End If
    40.  
    41. Exit Function
    42. err:
    43.    
    44.     If err.Number <> 0 Then
    45.         If err.Number = -2147024811 Then
    46.             MsgBox "The local device name is already in use.Please Disconnect and Run WMS", vbInformation
    47.             unmap_drives = False
    48.         Else
    49.             MsgBox err.Description, vbInformation
    50.             unmap_drives = False
    51.         End If
    52.     End If
    53. End Function
    54.  
    55. Public Function fGetDrives() As String
    56. 'Returns all mapped drives
    57.     Dim lngRet As Long
    58.     Dim strDrives As String * 255
    59.     Dim lngTmp As Long
    60.     lngTmp = Len(strDrives)
    61.     lngRet = GetLogicalDriveStrings(lngTmp, strDrives)
    62.     fGetDrives = Left(strDrives, lngRet)
    63. End Function
    64. Private Function RunProgram(servername As String, custcode As String, Production As String, Exename As String)
    65.     On Error GoTo Err1
    66.     Dim Exepath As String
    67.     Dim fso As New FileSystemObject
    68.     Exepath = servername & "\" & custcode & "_" & Production & "\" & Exename
    69.     MsgBox Exepath
    70.     If fso.FileExists(Exepath) Then
    71.       MsgBox Exepath & " :- File Not Found"
    72.     Else
    73.       Shell Exepath, vbNormalFocus
    74.     End If
    75.     'cboMapServer.Text, cboCusCode.Text, validtester, "_Production"
    76. Exit Function
    77. Err1:
    78.      MsgBox err.Description
    79.      Exit Function
    80. End Function

  37. #37

    Thread Starter
    Lively Member FiOh's Avatar
    Join Date
    Sep 2006
    Location
    Another World
    Posts
    104

    Unhappy Re: [RESOLVED] [EDITED] Help needed for Project!!

    Hi all,
    I have two errors when i run the program on a valid tester.
    Attached is the screenshot of the errors.
    Attached Images Attached Images   
    || ~ * FiOh * ~ ||

    Different personality n character... alone,
    difficult to understand n mysterious,
    for I am... Princess Cindistine @ Another World.
    You should know...
    P.C - R.N.A.F. Yeah, that is ME...

  38. #38

    Thread Starter
    Lively Member FiOh's Avatar
    Join Date
    Sep 2006
    Location
    Another World
    Posts
    104

    Re: [EDITED - New Errors] Help needed for Project!!

    Hi danasegarane,

    Here's the screen shot of the 'Mapping to
    Drive successfully mapped!' at the end of the status window even if the mapping failed.
    Attached Images Attached Images  
    || ~ * FiOh * ~ ||

    Different personality n character... alone,
    difficult to understand n mysterious,
    for I am... Princess Cindistine @ Another World.
    You should know...
    P.C - R.N.A.F. Yeah, that is ME...

  39. #39

    Thread Starter
    Lively Member FiOh's Avatar
    Join Date
    Sep 2006
    Location
    Another World
    Posts
    104

    Exclamation Re: [EDITED - New Requirements] Help needed for Project!!

    Hi danasegarane,

    Here's the new requirements for the project.
    Attached is the screen shot of how the newconfigfile.txt looks like.

    The MappingServer=168.232.32.23|netapp in the configfile.txt has been deleted. Right now the mapping location and the program to be launch is under all the individual customer code.

    In the screen shot, i have colored out the things to take note of. Those in RED are the Mapping Loaction while those in GREEN are the Program to Launch. As for the BLUE, they are the Separator (|).

    The format of the customer code is like this,
    BC1=mappinglocation1|mappinglocation2|mappinglocation3|mappinglocation4|mappinglocation5|Program to Launch 1|Program to Launch 2|Program to Launch 3|Program to Launch 4|Program to Launch 5|Version 1|Version 2|Version3

    Right now as you can see, there are some empty space in the Blue separator, those are for future use, we will reserve them 1st.

    What the program should do is to read the 1st 5 mapping location from this configfile.txt and pull it into the server to map, the same goes for the program to launch. But the program need to do a checking, check if in-between the blue separators (|), there is any content, if there isnt then this program shall not pull any data from it. Version number is only for SM4, it is in the last three '|'.

    Do you get what i mean?
    Sorry to trouble you again.

    FiOh
    ^^;;;
    Attached Images Attached Images  
    Attached Files Attached Files
    Last edited by FiOh; Nov 20th, 2006 at 04:05 AM.
    || ~ * FiOh * ~ ||

    Different personality n character... alone,
    difficult to understand n mysterious,
    for I am... Princess Cindistine @ Another World.
    You should know...
    P.C - R.N.A.F. Yeah, that is ME...

  40. #40
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: [EDITED - New Errors] Help needed for Project!!

    Part1
    Code:
    'Program Coding
    'Make the Cbo Program style to 2
    'and the same for Custumer code combo
    'This will restrict the user from enterting anything in the combo box
    Option Explicit
    
    '1st 2 lines For No-resize form
    Private dex As Long ' Declare variable dex as Long & Private
    Private dey As Long ' Declare variable dey as Long & Private
    
    Private Const ERROR_SUCCESS         As Long = 0
    Private Const MAX_DOMAIN_NAME_LEN   As Long = 128
    Private Const MAX_HOSTNAME_LEN      As Long = 128
    Private Const MAX_SCOPE_ID_LEN      As Long = 256
    
    Private Type IP_ADDRESS_STRING
        IpAddr(0 To 15)  As Byte
    End Type
    
    Private Type IP_MASK_STRING
        IpMask(0 To 15)  As Byte
    End Type
    
    Private Type IP_ADDR_STRING
        dwNext     As Long
        IpAddress  As IP_ADDRESS_STRING
        IpMask     As IP_MASK_STRING
        dwContext  As Long
    End Type
    
    Private Type FIXED_INFO
      hostname(0 To (MAX_HOSTNAME_LEN + 3))         As Byte
      DomainName(0 To (MAX_DOMAIN_NAME_LEN + 3))    As Byte
      CurrentDnsServer   As IP_ADDR_STRING
      DnsServerList      As IP_ADDR_STRING
      NodeType           As Long
      ScopeId(0 To (MAX_SCOPE_ID_LEN + 3))          As Byte
      EnableRouting      As Long
      EnableProxy        As Long
      EnableDns          As Long
    End Type
    
    Private Declare Function GetNetworkParams Lib "iphlpapi.dll" _
      (pFixedInfo As Any, _
       pOutBufLen As Long) As Long
    
    Private Declare Sub CopyMemory Lib "kernel32" _
       Alias "RtlMoveMemory" _
      (Destination As Any, _
       Source As Any, _
       ByVal Length As Long)
       
    'Declaration for map drive function
    '***********new
    Private Declare Function WNetCancelConnection Lib "mpr.dll" Alias "WNetCancelConnectionA" (ByVal lpszName As String, ByVal bForce As Long) As Long
    Private Declare Function WNetAddConnection2 Lib "mpr.dll" Alias "WNetAddConnection2A" (lpNetResource As NETRESOURCE, ByVal lpPassword As String, ByVal lpUserName As String, ByVal dwFlags As Long) As Long
    'Private Declare Function WNetCancelConnection2 Lib "mpr.dll" Alias "WNetCancelConnection2A" (ByVal lpName As String, ByVal dwFlags As Long, ByVal fForce As Long) As Long
    Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias _
        "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, _
        ByVal lpBuffer As String) As Long
    Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" _
        (ByVal nDrive As String) As Long
    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) 'suspends for process for some time
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Declare Function FormatMessage Lib "kernel32" Alias "FormatMessageA" (ByVal dwFlags As Long, lpSource As Any, ByVal dwMessageId As Long, ByVal dwLanguageId As Long, ByVal lpBuffer As String, ByVal nSize As Long, Arguments As Long) As Long
    Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
       hHandle As Long, ByVal dwMilliseconds As Long) As Long
    
    Private Type NETRESOURCE
        dwScope As Long
        dwType As Long
        dwDisplayType As Long
        dwUsage As Long
        pLocalName As String
        pRemoteName As String
        pComment As Long
        pProvider As Long
    End Type
    Private Const RESOURCETYPE_DISK As Long = &H1&
    Dim theNetResource As NETRESOURCE
    '8888888888888888888 new
       
       Private Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000
      
      
        Const WN_SUCCESS = 0 ' The function was successful.
        Const WN_NET_ERROR = 2 ' An error occurred on the network.
        Const WN_BAD_PASSWORD = 6 ' The password was invalid.
    
    'Const Machines = "J750_XX,UFLEX_XX,IFLEX_XX, TSG999_XX" 'To store the valid platform machine numbers.
    Const Machines = "J750-,UFLEX,IFLEX,is-s349a"
    'you can add your machine numbers here
    Const FORMAT_MESSAGE_ALLOCATE_BUFFER = &H100
    Const LANG_NEUTRAL = &H0
    Const SUBLANG_DEFAULT = &H1
    Const ERROR_BAD_USERNAME = 2202&
    Dim custname As String
    Dim validtester As String
    Private Const CB_FINDSTRINGEXACT = &H158 'constant varriable for find the value in the combo box
    
    'New codes
    Private Const ERROR_BAD_NETPATH = 53&
    Private Const ERROR_NETWORK_ACCESS_DENIED = 65&
    Private Const ERROR_INVALID_PASSWORD = 86&
    Private Const ERROR_NETWORK_BUSY = 54&
    Dim StartFlag As Boolean
    'For running the Version exe and wait untill it finishes --start
    Private sMappingservers(4) As String 'For stroring the mapping Server location
    Private sProgramlist(4) As String     'For Stroing the Program List
    
    Private Sub cboProgram_Click()
           On Error GoTo Progerror
        Dim strtext As String
        Dim FindPos As Integer
        strtext = "Please Select a Program Code"
            If Trim(cboProgram.Text) = "Please Select a Program Code" Then
               Exit Sub
            Else
                FindPos = SendMessage(cboProgram.hwnd, CB_FINDSTRINGEXACT, -1, ByVal strtext)
                 If FindPos > -1 Then
                  cboProgram.RemoveItem FindPos
               End If
            End If
    Exit Sub
    Progerror:
                MsgBox "An Error Occured .Sorry For the Inconvinence" & vbCrLf & err.Description
                Exit Sub
    End Sub
    
    Private Sub cmdExit_Click()
        'For Ending the program
        End
    End Sub
    Private Sub cboCusCode_Click()
        On Error GoTo CustError
        Dim FindPos As Integer
        Dim strtext As String
        'to get the custname
         Dim strposition As Integer ' For finding the postion of program code in program combo
         Dim objCust    'for opening the text file and search for custumer code
         Dim objCust1   'for opening the text file
         Dim strline    'to read the text file as lineby line
         Dim custcode As String 'for storing the custumer code
         Dim programname As String  'for finding the program code in the program combo
         Dim sVersion As String
         Dim i As Integer
         Dim x As Integer
         Dim strcustumernew
         cboProgram.Clear
         custcode = Trim(cbocuscode.Text) & "="   'for stroing the custumer code
         Set objCust = CreateObject("Scripting.FileSystemObject")
         'Real tester path
         
        Set objCust1 = objCust.OpenTextFile("C:\testsys\configfile.txt", 1)
          Do Until objCust1.AtEndOfStream   'loop through the entries in the text file.Read line by line .Untill the end of file is found
             strline = objCust1.ReadLine   'read line  by line
             If InStr(1, strline, custcode, vbTextCompare) > 0 Then  'search for BC1= or CT8= and so on... . if Found then the it will re
             'return a value greater than 0.
                 'After this find cut the line program code only
                 'eg if CT8=ProductionUI or BC1=ProductionUI is found then only cut the part ProductionUI
                 custname = Right(strline, (Len(strline) - InStr(1, strline, "=", vbTextCompare)))
                 'if the return value is like in the format SM4=STMP35XX_FT|STMP35XX_WS|NON_STMP35XX_FT
                  
                  If InStr(1, custname, "|", vbTextCompare) > 0 Then
                    ' then check the postion of | .If | found then split that string with respect to |
                     strcustumernew = Split(custname, "|")
                     If UBound(strcustumernew) > 0 Then
                        For i = 0 To 4
                                sMappingservers(i) = strcustumernew(i)
                        Next
                          x = 0
                        cboProgram.Enabled = True
                        cboProgram.AddItem "Please Select a Program Code", 0
                        For i = 5 To 9
                          If Len(strcustumernew(i)) > 0 Then
                           cboProgram.AddItem strcustumernew(i)
                           x = x + 1
                         End If
                        Next
                      If cboProgram.ListCount > -1 Then
                        cboProgram.ListIndex = 0
                      End If
                    End If
                  End If  'Loop through the array and add the program values in the program combo
                     
             End If
          Loop  'read the next line
         
        strtext = "Please Select a Customer Code"
        If StartFlag = True Then
              cboProgram.AddItem "Please Select a Program Code", 0
              cboProgram.ListIndex = 0
               Exit Sub
        Else
             
            If Trim(cbocuscode.Text) = "Please Select a Customer Code" Then
               Exit Sub
            Else
                FindPos = SendMessage(cbocuscode.hwnd, CB_FINDSTRINGEXACT, -1, ByVal strtext)
                 If FindPos > -1 Then
                  cbocuscode.RemoveItem FindPos
               End If
            End If
        End If
    Exit Sub
    CustError:
                MsgBox "An Error Occured .Sorry For the Inconvinence" & vbCrLf & err.Description
                Exit Sub
    End Sub
    Please mark you thread resolved using the Thread Tools as shown

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width