Word Document Properties


Listing 5-9 Using the GoTo Statement



Download 8,82 Mb.
Pdf ko'rish
bet118/207
Sana16.03.2022
Hajmi8,82 Mb.
#496217
1   ...   114   115   116   117   118   119   120   121   ...   207
Bog'liq
VBA For Dummies 5th Ed.pdf ( PDFDrive )

Listing 5-9
Using the GoTo Statement
‘ The restart point.
RestartCheck:
‘ Determine if the user has selected more than one row.
If ActiveWindow.RangeSelection.Rows.Count = 1 Then
‘ Get the cursor position.
130
Part II: Learning the Ropes 
10_046500 ch05.qxp 12/5/06 5:35 PM Page 130


CursorPosition = ActiveWindow.RangeSelection.Row
Else
‘ Tell the user to select only one cell.
Result = MsgBox(“Select only one cell!” + vbCrLf + _
“Choose the first row in the range?”,
_
vbExclamation Or vbYesNo, _
“Selection Error”)
‘ Determine if the user selected Yes.
If Result = vbYes Then
‘ Modify the selection.
Range(“A” + _
CStr(ActiveWindow.RangeSelection.Row)).Select
‘ Try the check again.
GoTo RestartCheck
End If
‘ Exit the Sub without further processing.
End
End If
This version of the code extends the error trapping found in the earlier
“Using the Select Case statement” section of this chapter. The original ver-
sion correctly identifies an error condition, but then it rudely ends without
helping you fix the problem. Rude programs make people mad, so it’s best to
provide some helpful assistance when you can.
Notice that the message box now displays a message that gives you a chance
to fix the error. 
Result
is a 
VbMsgBoxResult
data type, and it stores the
button click information.
When you click Yes, the code changes the current selection by using the
Range
function. Notice how the code converts the numeric 
ActiveWindow.
RangeSelection.Row
property value to a string and combines it with a
column letter for the 
Range
function. After the code moves the selection
point, it uses the 
GoTo
statement to return to a point before the row selection
check in the code. Because there’s only one row selected now, the check is
completed successfully.
Avoiding misuse of the GoTo statement
Many programmers misused the 
GoTo
statement so severely in the past that
most books tell you not to use it at all. Misuse of the 
GoTo
statement leads to
131

Download 8,82 Mb.

Do'stlaringiz bilan baham:
1   ...   114   115   116   117   118   119   120   121   ...   207




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish