same data contents exactly as excel1
Why don't you make a copy instead? Or do you just want to copy sheet1 from Excel1 to Excel2?
same data contents exactly as excel1
Why don't you make a copy instead? Or do you just want to copy sheet1 from Excel1 to Excel2?
Hi vb5prgrmr
No you cannot do that :)
Seems like you missed my previous post....
Check post 10
Is it that you can only ReDim an empty array?
No. You can only redim the last element of an array...
ReDim Preserve arrNames(0 To u)
Before you do that, you need to dim it as follows
Dim arrNames() as string
and then
ReDim arrNames(0 To u) as string
For example
Private Sub Command1_Click()
Dim arrNames() As String
u = 3
u = u + 1
ReDim Preserve arrNames(0 To u) As String
End Sub
@KSS: That thread is 5 years old :)
The original poster must have already got the answer by now...
Also I will never recommend DAO. ADO is much faster ;)
Hi Russel
Since the thread is already solved, I feel you need to also know why this happens... This is just for your FYI...
When using Preserve keyword, you can resize only the last array dimension. For example, if your array has only one dimension, you can resize that dimension because it is the last and only dimension. However, if your array has two or more dimensions, you can change the size of only the last dimension and still preserve the contents of the array.
For Example
Private Sub Command1_Click()
Dim MyArray() As String
ReDim Preserve MyArray(1, 1) '<~~ YOU CAN DO THIS
MyArray(1, 1) = "1. Blah Blah"
ReDim Preserve MyArray(1, 2) '<~~ YOU CAN DO THIS
MyArray(1, 2) = "2. Blah Blah"
ReDim Preserve MyArray(1, 3) '<~~ YOU CAN DO THIS
MyArray(1, 3) = "3. Blah Blah"
u = 2
ReDim Preserve MyArray(u, 3) '<~~ YOU CANNOT DO THIS
End Sub
An Alternative is
Private Sub Command1_Click()
Dim MyArray() As String, MyTempArray() As String
ReDim Preserve MyArray(1, 1) '<~~ YOU CAN DO THIS
MyArray(1, 1) = "1. Blah Blah"
ReDim Preserve MyArray(1, 2) '<~~ YOU CAN DO THIS
MyArray(1, 2) = "2. Blah Blah"
ReDim Preserve MyArray(1, 3) '<~~ YOU CAN DO THIS
MyArray(1, 3) = "3. Blah Blah"
u = 2
ReDim Preserve MyArray(u, 3) '<~~ YOU CANNOT DO THIS
ReDim MyTempArray(u, 1)
'Transfer data from MyArray to this array
End Sub
But my problem is that when adding the item to list box it will add "FOUND: wildcat" 7 times to the list box because there is 7 characters found in wlciadt.
First things first
Change this line
List1.AddItem "FOUND: " + v
to
List1.AddItem "FOUND: " & v
and then add one more line after that
Exit For
so that it looks like this
List1.AddItem "FOUND: " + v
Exit For
You missed out on one of the most important suggestion what your other friend gave ;)
use a flexgrid instead of listview.........
@Koolsid
I actually want the 'x' enabled. But I want to apply code to it.
@Jbennet
Thanks, that worked. Just one problem. Whether Yes or NO is chosen. The program still closes. Any reason why?
Oh Ok I understand :D
Is this what you want?
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If UnloadMode = vbFormControlMenu Then
Ret = MsgBox("Do You want to Exit?", vbOKCancel)
'~~> If user decides against it...
If Ret = vbCancel Then Cancel = 1
End If
End Sub
@koolsid
Does this code just disable the 'x' button?
Thats the conclusion im drawing from your image there.
It not only disable's the close button but also removes the 'close' option from the form's shortcut menu ;)
The API is very simple... All you need to do is copy and paste the code in the general declaration of the area....
Edit: Attaching a project sample for you :)
I have always loved the power of API's :D
This will help you...
Private Declare Function SHFileOperation Lib "shell32.dll" _
Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
'~~> Copy File/Folder
Private Const FO_COPY = &H2
'~~> Does not display file names
Private Const FOF_SIMPLEPROGRESS = &H100
Private Type SHFILEOPSTRUCT
hWnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAnyOperationsAborted As Long
hNameMappings As Long
lpszProgressTitle As Long
End Type
Private Sub VBCopyFolder(ByRef strSource As String, ByRef strTarget As String)
Dim op As SHFILEOPSTRUCT
With op
.wFunc = FO_COPY
.pTo = strTarget
.pFrom = strSource
.fFlags = FOF_SIMPLEPROGRESS
End With
'~~> Perform operation
SHFileOperation op
End Sub
Private Sub Command1_Click()
'~~> Copy Folder C:\temp\1 to C:\temp\2
'~~> Change this to relevant folders
Call VBCopyFolder("C:\temp\1", "C:\temp\2")
End Sub
A text box show current date(like 24-03-2009). I write in other textbox
3. I want when I write 3 then the textbox (24-03-2009) automatically increase month like 24-06-2009. how it possible?
Text1.Text = Format(DateAdd("m", Val(Text2.Text), Text1.Text), "dd-mm-yyyy")
Glad to have helped :)
Do remember to Mark your Thread "Solved", if the query is solved... ;)
Give me a moment...
Edit:
Ok I have checked the code again, it works fine... Can I see your project?
The problem starts here
toclear = toclear + "1"
and then continues to
toclear = toclear + "0"
and finally to
If toclear Like "1" Then
Do this...
Dim mycontrol As Control, toclear As Long
toclear = 0
For Each mycontrol In Me.Controls
If TypeOf mycontrol Is TextBox Or TypeOf mycontrol Is ComboBox Then
If Len(Trim(mycontrol)) = 0 Then toclear = toclear + 1
End If
Next
If toclear > 0 Then
clarifyclear = True
Else
clarifyclear = False
End If
If clarifyclear = False Then
'~~> Your rest of the code....
I have replied to your other post... It will give you a start... Incase you get stuck let me know.... :)
Hi Blocker
This works for me...
I have made few changes in the code to show it as an example. Please make relevant amendments for your original code...
Private Sub Command1_Click()
Dim mycontrol As Control
'~~> What is "newstudentry" in your code???
'~~> This works for me...
'~~>Me.Controls will ensure all controls in that form
'~~> are covered...
For Each mycontrol In Me.Controls
If TypeOf mycontrol Is TextBox Or _
TypeOf mycontrol Is ComboBox Then
'~~> combination of len and trim
If Len(Trim(mycontrol)) = 0 Then
MsgBox "empty"
Else
MsgBox "Not empty"
End If
End If
Next
End Sub
Hi rabbithaveit
I would suggest the API way as it gives you more flexibility... See picture attached...
Please place a Command Button on the form so that you can exit.
Paste this code in the general declaration of the form...
Option Explicit
Private Declare Function DeleteMenu Lib "user32" _
(ByVal hMenu As Long, ByVal nPosition As Long, _
ByVal wFlags As Long) As Long
Private Declare Function GetSystemMenu Lib "user32" _
(ByVal hwnd As Long, ByVal bRevert As Long) As Long
Private Const MF_BYPOSITION = &H400&
Private ReadyToClose As Boolean
Private Sub RemoveMenus(frm As Form, remove_restore As Boolean, _
remove_move As Boolean, remove_size As Boolean, remove_minimize As Boolean, _
remove_maximize As Boolean, remove_seperator As Boolean, remove_close As Boolean)
Dim hMenu As Long
'~~> Get the form's system menu handle.
hMenu = GetSystemMenu(hwnd, False)
If remove_close Then DeleteMenu hMenu, 6, MF_BYPOSITION
If remove_seperator Then DeleteMenu hMenu, 5, MF_BYPOSITION
If remove_maximize Then DeleteMenu hMenu, 4, MF_BYPOSITION
If remove_minimize Then DeleteMenu hMenu, 3, MF_BYPOSITION
If remove_size Then DeleteMenu hMenu, 2, MF_BYPOSITION
If remove_move Then DeleteMenu hMenu, 1, MF_BYPOSITION
If remove_restore Then DeleteMenu hMenu, 0, MF_BYPOSITION
End Sub
Private Sub cmdClose_Click()
ReadyToClose = True
Unload Me
End Sub
Private Sub Form_Load()
'~~> Remove the Close system menu item and the menu separator.
RemoveMenus Me, False, False, False, False, False, True, True
End Sub
'~~> Cancel if ReadyToClose is false.
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Cancel = Not ReadyToClose
End Sub
Hi hkdani, you don't need to "Microsoft Shell Controls and Automation reference" to just tackle the "date time window" in control panel. The code that I gave above is good enough :)
How to check both the cases IF and Else above code is Correct or i have to do any change.
what do you mean by the above?
BTW your above code is correct for "differences"
thank you.. it worked!
God bless (",)..
You are welcome :)
try with "Set"
Set Me.Sections("Section2").Controls("imgEmployee").Picture = frmMain.imgPic.Picture
To capture the image of the form, try this, Create two forms.. Form1 and Form2. Place a commandbutton in form1 and picturebox control in form2.
Code for Form1
Option Explicit
Private Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" _
(ByVal wCode As Long, ByVal wMapType As Long) As Long
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal _
bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Const VK_MENU = &H12
Private Const VK_SNAPSHOT = &H2C
Private Const KEYEVENTF_KEYUP = &H2
Private Sub Command1_Click()
#Const WINDOWS_VERSION = "Windows2000"
Dim alt_key As Long, frm As New Form2
'~~> Capture image of form in clipboard.
alt_key = MapVirtualKey(VK_MENU, 0)
keybd_event VK_MENU, alt_key, 0, 0
DoEvents
#If WINDOWS_VERSION = "Windows2000" Then
keybd_event VK_SNAPSHOT, 0, 0, 0
#Else
keybd_event VK_SNAPSHOT, 1, 0, 0
#End If
DoEvents
keybd_event VK_MENU, alt_key, KEYEVENTF_KEYUP, 0
DoEvents
frm.Picture1.Picture = Clipboard.GetData(vbCFBitmap)
frm.Show
End Sub
Code for Form2
Option Explicit
Private Sub Form_Resize()
Picture1.Move 0, 0, ScaleWidth, ScaleHeight
End Sub
After this, if you want you can export the image from picture1 to harddisk and send it to the next pc....
Hope this helps...
If you are looking to interact with it then my suggestion is that you use the inbuilt calendar of vb6....
else here is the code
Private Sub Command1_Click()
'~~> launces the date time window in control panel
Call Shell("rundll32.exe shell32.dll,Control_RunDLL timedate.cpl")
End Sub
Reading the contents of text file is not a problem. i couldn't understand your rest of the query... Do you mean that if there is a word "True" in your text document which if found, you want to display the message "Finish"... if yes then try this
Sub ReadtextFile()
Dim intEmpFileNbr As Integer, Entireline As String
intEmpFileNbr = FreeFile
'~~> Change this with the relevant filename
strEmpFileName = "C:\Temp\Test.txt"
'~~> open the file as readonly
Open strEmpFileName For Input As #intEmpFileNbr
Do Until EOF(intEmpFileNbr)
'~~> Read line
Line Input #intEmpFileNbr, Entireline
If InStr(1, Entireline, "True") <> 0 Then
MsgBox "Finish"
Exit Do
End If
Loop
'~~> Close file
Close #intEmpFileNbr
End Sub
the problem is you are trying to launch a PDF file, not an EXE file. If you want to open the pdf file, you'll have to use the path to adobe. Something like "c:\program files\adobe\adobe.exe aa.pdf" or something along those lines. the Shell function doesn't decipher extentions. It runs an application. Plain and simple. For a POSSIBLE solution to launching a program based on the extention (in cahoots with the registries, HKCR) you might want to look at the API call "shellexecute." That one does wonders ;)
You are right that it runs only applications. Even if you mention the filename with the path and the corresponding exe ("c:\program files\adobe\adobe.exe aa.pdf") or as a matter of fact ("c:\windows\notepad.exe aaa.txt") it still won't run... that's what i am trying to imply. working on it right now. should come up with the code ASAP :-)
So what can I do with the problem? Can you make the file for me please?
Thanks! I hope will here from you soon.
seyha
Sure, I'll give the code in the evening when i come back from office.... Leaving for office now :-)
Try using commondialog controls with FSO (file system objects....)
Call statement Transfers control to a Sub procedure, Function procedure, or dynamic-link library (DLL)procedure.
I believe that you cannot use "CALL" to call a file which is not executable.
same goes with SHELL...
Call Shell(AppName, 1) Where AppName contains the path of the Executable file.
try it with any other directory and try calling an executable.. it will work.
If you try calling a .txt or .bmp, it will give you the same error message...
ADO is supposed to be quick...
is your table indexed??? (I am assuming that you are aware of how to set a relationship with the database using ADO so i am not checking that....)
will be back from office in evening. will check your reply later :mrgreen:
Have you checked your nearest software dealer??
In case you want it to buy online then simply click the link below or copy and paste the link in your browser...
you'll find plenty of choices...
http://a9.com/visual%20studio%206?src=amz
happy buying :cool:
hmmm
there goes my idea of playing with strings.... ;) is it still insecure if we define those constants in activex controlls??? can they be reverse engineered?
anyways anxiously waiting for your code...
Simply because, data stored in a access database can be hacked easily... I have a software which can decode the password protected access database...
Would really appreciate if you can send me the code. i'll try that out as well.
Can we play around with strings??? for example lets take a string "WORLD" suppose i want to replace "O" with "cv44v" or any other letter say "L" with say "df5gh" and write an active x dll for the same... that way we can encrypt/decrypt the PASSWORD and USERNAME... (it is just a thought...)
yes i want to save the username and password in a text file and not in a database.
i want the username and password both to be encrypted. when anyone opens the file in a note pad it should somehow look like this...
[USERS]
fgdfs565dyjtj ==> encrypted username1
ghhghfgjh ==> encrypted username2
hfjhgkjgjk ==> encrypted username3
hjkgjk ==> encrypted username4
[PASSWORD]
gfhrty67676 ==> encrypted password for username1
hyrhryhyrh ==> encrypted password for username2
hrhyrhyhryh ==> encrypted password for username3
gfdhyt6477 ==> encrypted password for username4
the program should work viceversa as well. i mean decrypting the data
I didn't find creating login screens and saving the data in access database difficult...
However, I was wondering if there is any other way we could do that, i mean saving the username and passwords in any other file rather than a database and encrypting the same...
Rgds