Return to AskMe Archive Main Page
Return to Main PowerUsers.info Main Page
Category : Visual Basic
PowerUsers.info - Paul Doherty Askme Archive of Questions and Answers
----------------------------------------------------------------------
FAQId : 6573895
Subject : V.B
Question : HI,
Can u pls tell me that
what exactly Loop does ? and what is the differnece between Do while Loop and
While Wend
thank u in advance
pls reply sooon
Answer : A loop is a programming device that allows you to do a particular
process more than one time, usually when you don't know for sure how many times
you will need to process it (a "for" loop is usually used when you know
before-hand how many times to loop).
A good use of a while loop is a control trigger to wait for a certain thing to
be true before continuing with your program. For example let's say you want to
get positive numeric input from the user, and want to be sure it's valid input.
With a loop this can be done in a nice short (elegant) way:
done = FALSE
while done == FALSE
____Prompt user for input
____assign input to variable
____check to see if input is a number and is positive
____if it is, set done = TRUE
endwhile
Can you see that this loop will continue indefinitely until the user inputs a
number that is positive?
The difference in a While/WEnd and a Do/While loop is that a Do/While loop will
always have its contents run at least *once* since it's check for looping is at
the END of the loop, while a While/WEnd type of loop checks before entering the
loop and can possibly never have its contents run even once.
--
Paul Doherty
http://members.home.net/iqueue
DOS/Windows Utilities
Rating :
----------------------------------------------------------------------
FAQId : 6609818
Subject : SendKeys
Question : Hi all,
I have to solve an urgent problem: I must send the characters "ctrl" and
"insert" from VB6 to an external application, to copy the previous selected
text.
This is my code:
Set appAskSam = New AskSam.Application
appAskSam.Visible = True
appAskSam.Documents.Open Path appAskSam.ActiveDocument.Search StringToSearch
appAskSam.ActiveDocument.StartOfDoc
appAskSam.ActiveDocument.EndOfDoc True
SendKeys "{^}" + "{INSERT}"
appAskSam.Quit 0
Set appAskSam = Nothing
With this instruction
appAskSam.ActiveDocument.EndOfDoc True
I select te text
and the line
SendKeys "{^}" + "{INSERT}"
doesn't work
appAskSam is my external application, askSam 4 Trial
What can I do?
Thanks in advance.
Answer : Hmmm if your Word document ends up with:
a-a-c-c-d
OR
b-b-e-e-d
it would seem the problem lies either with your loop construct (unlikely) or
with the format of the data you retrieve from the "database", no? The problem
doesn't appear to be with your copy/paste operation or sendkeys since if they
work for one they should work for all.
Answer : Try using the more standard CTRL-C for copy and CTRL-V for pasting.
Here is a sample app I wrote that does some text entry and then copies and
pastes part of the text:
Private Sub Form_Load()
ReturnValue = Shell("C:\Program Files\Windows NT\Accessories\wordpad.exe", 1)
AppActivate ReturnValue
SendKeys "Hi" & vbCrLf, True
SendKeys "Gr8" & vbCrLf, True
SendKeys "abcdefghijklmnopqrstuvwxyz", True
SendKeys "{HOME}", True
SendKeys "{INSERT}", True
SendKeys "My name is Paul", True
SendKeys "{HOME}", True
SendKeys "+" + "{END}", True
SendKeys "^" + "C", True
SendKeys "{END}", True
SendKeys "{ENTER}", True
SendKeys "^" + "V", True
End Sub
The "+" above is the SHIFT key.
The resulting text from running the above:
Hi
Gr8
My name is Paulpqrstuvwxyz
My name is Paulpqrstuvwxyz
which demonstrates that the INSERT worked, since I am overwriting the ABCs I
typed, and the copy/paste worked since I have two copies of the last line.
--
Paul Doherty
http://members.home.net/iqueue
DOS/Windows Utilities
FUQuestion : Thanks Paul,
but with "^" + "C" it doesn't copy nothing to me.
Now the question is different:
appAskSam.ActiveDocument.Search SearchedString
Debug.Print SearchedString
appAskSam.ActiveDocument.StartOfDoc
appAskSam.ActiveDocument.EndOfDoc True
SendKeys "^" + "{INSERT}", True
these instruction are in a cicle and "SearchedString" is always different and
present in the document;
as result I have 5 outputs (like the number of cycled), but only 3 of those are
different. For example I have
a-c-c-e-e instead of a-b-c-d-e
I tryed with and without the true option.
FUQuestion : Ok.
Imagine that you have 5 keys (a, b, c, d, e) and you have to search them in a
database. This database is calle askSam and it's not normal, because it looks
like a text editor where every page is a record and it doesn't recognize SQL
commands.
My problem is retrieve the records and copy them in a word document.
These are my VB steps:
1. Open a new word document (done)
2. Open the askSam file where I'll search the keys (done)
3. Read the key from a text file (done)
4. Search the value in the askSam db (done)
5. Select the entire page (remember that it looks like a text editor) (done)
6. Copy the page
7. Paste it in Word
8. Return to the step 3 until EOF
In Word, instead of the entire record of a-b-c-d-e, I have (for example):
a-a-c-c-d
OR
b-b-e-e-d
or something else.
Thanks a lot.
Need More Information : I guess I'm not getting what you are trying to do. Can
you show me the text of an example document and then what you're trying to
achieve?
----------------------------------------------------------------------
FAQId : 7157627
Subject : compress a file by code
Question : If I want to compress a file ( or a folder ), how to do this by the
code.
Can I use WinZip to do such thing.If it is how to do it by code.Please, Do not
forget to give me the reverse way.
Thank you so much for your
works and responses,
Answer : I created a standard Form and added a single command button to it.
Below is the code to use to invoke WinZip and compress some files:
Private Sub Command1_Click()
params = " -min -a -r c:\test1.zip c:\windows\*.bmp"
Shell ("c:\program files\winzip\winzip32.exe" & params)
End Sub
Add a second button (or just erase the code and put the following in) and use
the code below to extract the files:
Private Sub Command1_Click()
params = " -min -e -o c:\test1.zip c:\temp\stuff4"
Shell ("c:\program files\winzip\winzip32.exe" & params)
End Sub
--
Paul Doherty
http://home.attbi.com/~bitbucket911
DOS/Windows Utilities
Rating : PowerUsers.info - Paul Doherty Askme Archive of Questions and Answers