|
Het2109 wrote:
ya, but suppose i have a group box and my textbox/combo box is placed on the group box, then how to access it. thru this code i get groupbox, but not the controls that are placed inside the groupbox.
Then handle that case in the loop, either by having a secondary loop, or better, set up the loop as a function that takes a controls collection as a parameter. eg:
Public Sub RecurseControls(ByVal ctls As ControlCollection)
Dim c As Control
For Each c In ctls
If TypeOf c Is TextBox Then
Debug.WriteLine(c.Text)
ElseIf TypeOf c Is GroupBox Then
RecurseControls(c.Controls)
End If
Next
End Sub
You call this function, passing in Me.Controls to start with.
--
Ian Darling
"The moral of the story is that with a contrived example, you can prove anything." - Joel Spolsky
|
|
|
|
|
Hello everybody!
I'm new to the Visual basic.net and I'm trying to create a ActiveX dll project to use on server side in my asp pages.
I have created several of similar projects in vb6 and never had a problem.
I created a new Class library project. Added ComClass tag with ClassID, InterfaceId and EventsID. I checked the "Register for COM Interop" in project properties.
I created test asp page that calls Server.CreateObject("appname.classname") and this is when I get the error "object reference not set to an instance of an object"
Does any one know why this happens?
Thank you for any help!
iluha
|
|
|
|
|
I found the problem!
Public Sub New()
MyBase.New()
g_dbConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
End Sub
as soon as i commented the "g_dbConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=""" line it started to work.
Can some one tell me, can i have extra code in the sub new ?
besides the MyBase.New()?
|
|
|
|
|
I've been assigned the task of creating a batch file to copy a set of files from one directory to another every night. It needs to be over a windows network.
My source files are organized like this:
\\server\clients\smith\network_diagram\diagram.htm
\\server\clients\brown\network_diagram\diagram.htm
\\server\clients\johnson\network_diagram\diagram.htm
\\server\clients\doe\network_diagram\diagram.htm
Destination needs to be like this:
\\server\network_diagram\smith\diagram.htm
\\server\network_diagram\brown\diagram.htm
\\server\network_diagram\johnson\diagram.htm
\\server\network_diagram\doe\diagram.htm
I need to avoid hard coding each directory in the batch file in case we gain new clients. My problem is creating a loop in a Windows Command Batch file so I'm thinking a small VB app is the way to go. I'm not too experienced in VB at all so I would appreciate help doing a loop like the following:
For all client folders in "\\server\clients\" copy "\\server\clients\client name\diagram.htm" to "\\server\network_diagram\client name\diagram.htm"
|
|
|
|
|
Here is some code that will go through the directory copy you files.
Option Explicit
Private Const MAX_PATH = 260
Private Const FILE_ATTRIBUTE_DIRECTORY = &H10
Private Const INVALID_HANDLE_VALUE = -1
Private Type FileTime
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FileTime
ftLastAccessTime As FileTime
ftLastWriteTime As FileTime
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * MAX_PATH
cAlternate As String * 14
End Type
Private Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long
Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
Private Sub Form_Load()
On Error Resume Next
Dim hSearch&, FileData As WIN32_FIND_DATA, aFolderName$
hSearch& = FindFirstFile("\\server\clients\*.*", FileData)
If hSearch& <> INVALID_HANDLE_VALUE Then
Do
If FileData.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY Then
aFolderName$ = Mid$(FileData.cFileName, 1, InStr(1, FileData.cFileName, vbNullChar) - 1)
Select Case aFolderName$
Case ".", ".." 'skip
Case Else
CopyFile "\\server\clients\" & aFolderName$ & "\diagram.htm", "\\server\network_diagram\" & aFolderName$ & "\diagram.htm", True
End Select
End If
FileData.cFileName = ""
Loop While FindNextFile(hSearch&, FileData)
FindClose (hSearch&)
End If
End Sub
iluha
|
|
|
|
|
Thank you. It looks much more than I expected. I need to get VS.NET on here then I can try it out.
|
|
|
|
|
Hi
I want to open any document without the .exe file to open it. Example.
If I using shell("c:\program files\microsoft office\office\winword.exe c:\temp\mydoc.doc")
I dont't wanna that.
How i can only put Shell("c:\temp\mydoc.doc") or other command to open it.
Johnny Lizardo
|
|
|
|
|
The reason is clear..
Many PC have differents office version and I can't specify the path correctly.
|
|
|
|
|
|
Hi
Look, i don't know.. but this don't works. This is a command for vb.net?. Or give me more info about that.
Johnny Lizardo
|
|
|
|
|
VB5/6 declaration:
Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
or better (but only for 2000/XP) the unicode function:
Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteW" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
VB.NET declaration:
Declare Auto Function ShellExecute Lib "shell32.dll" (ByVal hwnd As IntPtr, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Integer) As Integer</pre lang=vbnet>
nShowCmd & return value constants declaration:
<pre lang=vb>Public Const SW_HIDE = 0
Public Const SW_MAXIMIZE = 3
Public Const SW_MINIMIZE = 6
Public Const SW_RESTORE = 9
Public Const SW_SHOW = 5
Public Const SW_SHOWDEFAULT = 10
Public Const SW_SHOWMAXIMIZED = 3
Public Const SW_SHOWMINIMIZED = 2
Public Const SW_SHOWMINNOACTIVE = 7
Public Const SW_SHOWNA = 8
Public Const SW_SHOWNOACTIVATE = 4
Public Const SW_SHOWNORMAL = 1
Public Const ERROR_FILE_NOT_FOUND = 2&
Public Const ERROR_PATH_NOT_FOUND = 3&
Public Const ERROR_BAD_FORMAT = 11&
Public Const SE_ERR_ACCESSDENIED = 5
Public Const SE_ERR_ASSOCINCOMPLETE = 27
Public Const SE_ERR_DDEBUSY = 30
Public Const SE_ERR_DDEFAIL = 29
Public Const SE_ERR_DDETIMEOUT = 28
Public Const SE_ERR_DLLNOTFOUND = 32
Public Const SE_ERR_FNF = 2
Public Const SE_ERR_NOASSOC = 31
Public Const SE_ERR_OOM = 8
Public Const SE_ERR_PNF = 3
Public Const SE_ERR_SHARE = 26
VB5/6 example
Private Sub OpenFile(ByVal File As String)
ShellExecute(Me.hWnd, "open", File, 0, 0, SW_NORMAL)
End Sub
See ShellExecute Function on MSDN
Hope this helps you out
greetz
*Niels Penneman*
Software/Dev Site Personal Site
|
|
|
|
|
Men.. You're the men,.
Thankk a lottt.
Johnny Lizardo
|
|
|
|
|
Please Help!!
I can not connect to my Access Database because None of the ODBC Providers will work.
The only one that tries to work is the Fox pro Connection but that still gives me a error when I try to connect to the database.
Regards
Marc
marclaz@netactive.co.za
|
|
|
|
|
Hi Marc,
What's the connection string that you're using?
Datagrid Girl
|
|
|
|
|
wat is the code for matrix?can VB link wiv MATLAB?how?
|
|
|
|
|
When I use a ListView control in VB.NET, the control doesn't repaint its ColumnHeader s and sometimes the grid too at runtime (when scrolling, ...). I turned on and off visual styles support but the headers won't repaint correctly. Anyone who knows more about this?
greetz
*Niels Penneman*
|
|
|
|
|
hey,,
can anyone tell me that how can i install the keyboard hook in VB6 to capture the ALT+TAB, CTRL+ESC, and the like keyboard events and disable them.
Thanx
Vivek
|
|
|
|
|
I have a object call Request that has a sub object of Document. The object Request contains information about a request for a document. It includes a sub object called Document that contains all the details about the document being requested. I want to bind to the request object and show the document.title property in the same datagrid without haveing to do any navigation such as occurs with tables which are linked. For example I want my datamember to be "Document.Title". Any suggestions would be appreciated.
|
|
|
|
|
All I want to know is, "is the screensaver running or not?".
This problem seems to be much harder than it should be.
I'm attempting to use SystemParametersInfo api call to determine if it is running or not, but I keep getting an err.LastDllError.
Language: VB.Net
Platform: Win XP
Can anybody stop this coder from suiciding over something that should be fairly easy?
|
|
|
|
|
|
Thanks for replying Rage.
This is the code I am using and am getting back an error code (lastDllError code I think) of 998.
I can't seem to find any information on the error codes for SystemParametersInfoA.
Also, as VB.Net doesn't have any "Any" type I have used the VariantType, Object type, and boolean type all to no avail.
'My Code
Private Declare Function SystemParametersInfo _
Lib "user32" _
Alias "SystemParametersInfoA" _
(ByVal uiAction As Long, _
ByVal uiParam As Long, _
ByRef pvParam As VariantType, _
ByVal fWInIni As Long) As Boolean
Private Const SPI_GETSCREENSAVEACTIVE As Long = &H10
Private Const SPI_GETSCREENSAVERRUNNING As Long = &H72
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim p_lngRtn As Long
p_lngRtn = SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, bRunning, False)
If bRunning Then
Beep()
End If
If p_lngRtn = 0 Then
Debug.WriteLine(Err.LastDllError)
End If
End Sub
|
|
|
|
|
OK. All of your code is good except for one thing. Change all of your 'Long's to Integers. Long's in VB.NET are 64-bit integers and 32-bit in VB6. This is one of your problems. The other is that your VariantType just needs to be an integer. All the pvParam is returning is a boolean value saying True or False. When you call a function that has an ANy type in it, you have to think ahead and replace the Any with the type that you EXPECT to get back. In this case, a 32-bit Integer would work. The corrected code look like this:
Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" _
(ByVal uiAction As Integer, _
ByVal uiParam As Integer, _
ByRef pvParam As Integer, _
ByVal fWInIni As Integer) As Boolean
Private Const SPI_GETSCREENSAVEACTIVE As Integer = &H10
Private Const SPI_GETSCREENSAVERRUNNING As Integer = &H72
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim p_lngRtn As Integer
Dim bRunning As Boolean
p_lngRtn = SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, bRunning, False)
If p_lngRtn = 0 Then
Debug.WriteLine(Err.Description)
End If
If bRunning Then
Beep()
End If
End Sub
Also, when calling into the API, exceptions will not be thrown, and the Err object will not be set at all. You would have to use the return value, 'p_lngRtn' is your code, to determine that an error HAS occured, then you would have to call the API function GetLastError to get the actual error that occured. Your's was probably something like '87 - The parameter is incorrect'.
RageInTheMachine9532
|
|
|
|
|
Yup!.. that's solved it alright!
I don't think I woulda ever thought about the difference between vb6 and vb.net integers..
Thanks!
Just one question though, you don't happen to know where the error codes are listed for api errors? I was getting an error code of 998 and couldn't find out what it meant to be able to fix this problem..
Thanks again!
|
|
|
|
|
998 wouldn't have told you what the problem was either. It means "Invalid access to memory location." The only thing it would have told you is that your passing an invalid reference to a variable, or memory location.
The complete list of Win32 API errors can be found here[^].
RageInTheMachine9532
|
|
|
|
|
Hi
I'm new to VB.Net and when I try to load an existing VB6 project I get a "Security Error"
When I try to start a new project in VB.Net I get a "Required permissions cannot be acquired" error
Can anybody point me in the right direction as to what to do?
Thanks
Stephen
|
|
|
|