473,322 Members | 1,690 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Logic problem with absolute value

I get an "Ambiguous Match Exception" when I try to run the code below. I
need |x1 - x2| 80 and |y1 - y2| 100, and I want to just loop until
this condition is true.

horz1 = Int(Rnd() * 469)
vert1 = Int(Rnd() * 245)

Do
horz2 = Int(Rnd() * 469)
vert2 = Int(Rnd() * 245)

Loop Until (Math.Abs((horz1 - horz2) 80)) And (Math.Abs((vert1 -
vert2) 101))

Can anybody enlighten me?

Thanks
--
Jeff Ciaccio
Physics and AP Physics Teacher
Sprayberry High School; Marietta, GA
Blog: http://sprayberry.typepad.com/ciaccio

Jun 28 '08 #1
5 1660
You are attempting to call Math.Abs with a Boolean as the parameter:

(horz1 - horz2) 80

and

(vert1 - vert2) 101

You need to rationalize your parentheses.

Loop Until Math.Abs(horz1 - horz2) 80 And Math.Abs(vert1 - vert2) 101

You might also look at using AndAlso instead of And because this will 'short
circuit' the test if the first part of the test resolves to False.
"Jeff Ciaccio" <no****@noreply.orgwrote in message
news:eE**************@TK2MSFTNGP05.phx.gbl...
>I get an "Ambiguous Match Exception" when I try to run the code below. I
need |x1 - x2| 80 and |y1 - y2| 100, and I want to just loop until
this condition is true.

horz1 = Int(Rnd() * 469)
vert1 = Int(Rnd() * 245)

Do
horz2 = Int(Rnd() * 469)
vert2 = Int(Rnd() * 245)

Loop Until (Math.Abs((horz1 - horz2) 80)) And (Math.Abs((vert1 -
vert2) 101))

Can anybody enlighten me?

Thanks
--
Jeff Ciaccio
Physics and AP Physics Teacher
Sprayberry High School; Marietta, GA
Blog: http://sprayberry.typepad.com/ciaccio
Jun 28 '08 #2
That must have been it- Thanks!! It seems to work this way and when I add an
extra set like this
Loop Until (Math.Abs(horz1 - horz2) 80) And (Math.Abs(vert1 - vert2) >
101)

I never realized that too many parenthesis could cause problems as long as
they were all closed properly.

Thanks again,
Jeff (VB Neophyte)

Jun 28 '08 #3
It wasn't so much a matter of too many parentheses - It was a matter of them
being in the wrong places.

Because the logic is left to right you don't actually need any at all.

You really only need them when you need to force something to be evaluated
out of the normal sequence.

Overuse of parentheses can cause a maintenance nightmare.
"Jeff Ciaccio" <no****@noreply.orgwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
That must have been it- Thanks!! It seems to work this way and when I add
an extra set like this
Loop Until (Math.Abs(horz1 - horz2) 80) And (Math.Abs(vert1 - vert2) >
101)

I never realized that too many parenthesis could cause problems as long as
they were all closed properly.

Thanks again,
Jeff (VB Neophyte)
Jun 28 '08 #4
Two more quick questions if you don't mind.
1) Is there a way to rotate a picture box in VB Express 2008? I don't see
an angle or rotation property, but I'm guessing there is a way.
2) I've got 6 .bmps in My Resources, and I've set their Build Action to
"Embedded Resource", but cannot figure out the qualifier to set them at
runtime. I've got die1.bmp, die2.bmp, etc., and I've tried
picDie.ImageLocation = My.Resources."die" &x &".bmp" as well as "c:\die" &x
&".bmp" where x is a variable evaluated at runtime.

Any thougts?
"Stephany Young" <noone@localhostwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
It wasn't so much a matter of too many parentheses - It was a matter of
them being in the wrong places.

Because the logic is left to right you don't actually need any at all.

You really only need them when you need to force something to be evaluated
out of the normal sequence.

Overuse of parentheses can cause a maintenance nightmare.
"Jeff Ciaccio" <no****@noreply.orgwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>That must have been it- Thanks!! It seems to work this way and when I add
an extra set like this
Loop Until (Math.Abs(horz1 - horz2) 80) And (Math.Abs(vert1 - vert2) >
101)

I never realized that too many parenthesis could cause problems as long
as they were all closed properly.

Thanks again,
Jeff (VB Neophyte)
Jun 28 '08 #5
First of all, if you post follow-up questions in a thread then they should
be directly related to the original question, otherwise, anyone who wasn't
watching this particular thread will never see them.

But ...

1. Why on earth would you want to rotate a picture box? A PictureBox
control is, in effect, nothing more than a canvas upon which you display a
image. If you mean 'is there a way to rotate an image?' then you will have
better luck postin your 'properly' question to
microsoft.public.dotnet.framework.drawing.
2. My.Resources exposes a number of properties and/or methods that allow you
to retrieve a resource by it's name. F1 and/or intellisense is your friend
for finding which property/method will work best for you.
"Jeff Ciaccio" <no****@noreply.orgwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
Two more quick questions if you don't mind.
1) Is there a way to rotate a picture box in VB Express 2008? I don't see
an angle or rotation property, but I'm guessing there is a way.
2) I've got 6 .bmps in My Resources, and I've set their Build Action to
"Embedded Resource", but cannot figure out the qualifier to set them at
runtime. I've got die1.bmp, die2.bmp, etc., and I've tried
picDie.ImageLocation = My.Resources."die" &x &".bmp" as well as "c:\die"
&x &".bmp" where x is a variable evaluated at runtime.

Any thougts?
"Stephany Young" <noone@localhostwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
>It wasn't so much a matter of too many parentheses - It was a matter of
them being in the wrong places.

Because the logic is left to right you don't actually need any at all.

You really only need them when you need to force something to be
evaluated out of the normal sequence.

Overuse of parentheses can cause a maintenance nightmare.
"Jeff Ciaccio" <no****@noreply.orgwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>>That must have been it- Thanks!! It seems to work this way and when I
add an extra set like this
Loop Until (Math.Abs(horz1 - horz2) 80) And (Math.Abs(vert1 - vert2) >
101)

I never realized that too many parenthesis could cause problems as long
as they were all closed properly.

Thanks again,
Jeff (VB Neophyte)
Jun 28 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: KathyB | last post by:
Hi, I have the following script in an aspx html: <script language="javascript"> function pop_window() { var confirmWin = null; confirmWin = window.open('Scanned.aspx', 'SerialNumbers',...
1
by: Sujith Jagini | last post by:
------------------------------------------------------------------ <input type="hidden" name="__VIEWSTATE" value="dDwtMTUzMzQ4ODY4ODs7Pleb3NLElxrFpPbkFWoEst9bdqIM" /> <span id="Label1"...
29
by: Tom wilson | last post by:
I can't believe this is such an impossibility... I have an asp.net page. It accepts data through on form fields and includes a submit button. The page loads up and you fill out some stuff. ...
3
by: lawrencec | last post by:
Hi there, I'm trying to add the values of a number of form fields and to get a result at the end. It must loop and be able to dynamically update the result of calculation. I have attached the...
19
by: pamelafluente | last post by:
Hi Guys, I am trying to include my little script in my html report. I have done an external JS file which contains it. If you remember, you have helped me to detect if the asp page was present...
10
by: ellie2905 | last post by:
Hello, I am new to this forum and I am glad I found it because it seems that it will help me with my problem.I have creates a site using jsf components like grid panels and buttons.In the mozilla...
1
by: Anuj | last post by:
Hi, since sometime I'm stuck in a problem where I want to check or uncheck all the checkboxes. If I'm choosing name for the checkbox array as 'chkbx_ary' then I'm able to check/uncheck all the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.