?
Solved

Urgent but Simple....I think. Aid in manipulating these two code segments.

Posted on 2003-03-25
18
Medium Priority
?
186 Views
Last Modified: 2012-05-04
hi....this first section of code draws a 70mm length of a 8 - 12 Ghz sine wave. The frequency is changed using a scroll bar. I'm not sure how it works...I'm new to programming, but it does what it needs to.

Private Sub DrawWave()
 
  Me.PicWave.Cls
  ' number of sine waves per box = 70mm/wavelength(mm), ie 2.33 for 10ghz
 
  Dim NumWaves As Single
  Dim Wavelength As Double
  Dim GHZFreq As Double
  Dim x As Single
  Dim y As Double
  Dim Freq As Single
 
  GHZFreq = scrGunDiode.Value / GHZFactor
  Wavelength = 300 / GHZFreq
  NumWaves = WIDTHmm / Wavelength
 
  For x = 0 To WIDTHmm Step 0.1
     
     y = Sin(x * NumWaves * (360 / WIDTHmm) * PI / 180) * AMPLITUDE
     Me.PicWave.PSet (x, y), vbRed
 
  Next x
 
  Me.lblGunDiodeHz = CStr(Val(scrGunDiode.Value / GHZFactor)) & " GHz"

End Sub


The next section of code is designed to convert the 8 - 12 GHz signal, convert it into the corresponding wavelength. It then changes the original wavelength to the wavelength it changes to when it passes througha waveguide, called ComputeWaveGuideWavelength.
Public Function ComputeWavelength(dblFrequency As Double) As Double

  ComputeWavelength = 3 * 10 ^ 8 / dblFrequency

End Function

Public Function ComputeWaveGuideWavelength(dblFrequency As Double) As Double

  Dim dblOrigWaveLength As Double

  dblOrigWaveLength = ComputeWavelength(dblFrequency)

  ComputeWaveGuideWavelength = dblOrigWaveLength / Sqr(1 - ((dblOrigWaveLength / 0.04572) ^ 2))

End Function

these pieces of code were given to me by two different experts and hence they use different variable names. What I'm trying to do is instead of drawing the original wavelength is to draw the wavelength generated using ComputeWaveGuideWavelength. The second snippet of code is in a code module, not in the form module. How and what would I change to achieve this???

Thanks, Nick
0
Comment
Question by:nickclaridge
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 5
  • 4
18 Comments
 

Author Comment

by:nickclaridge
ID: 8205048
The scroll bar should still be able to change the original wavelength. This should then cause ComputeWaveGuideWavelength to calculate the new waveguide wavelength which it passes to the DrawWave function. Not being too familiar with programming I'm not sure how to do this.
0
 
LVL 1

Expert Comment

by:timd_jones
ID: 8205301
If I understand what you are trying to do, try inserting this line:

Wavelength = ComputeWaveGuideWavelength(Wavelength)

after the original line that begins "Wavelength = "

It also looks like the Sqr function call in ComputeWaveGuideWavelength will fail if the calculation (1 - ((dblOrigWaveLength / 0.04572) ^ 2)) yields a negative number. It is possible you will never have a problem that, but if you receive a run-time error 5 : "Invalid procedure call or argument", that may well be the problem. I don't know if taking the absolute value (Abs()) of the result will yield a valid result.

0
 

Author Comment

by:nickclaridge
ID: 8205383
I did receive a run-time error 5 and it pointed me to the line with the sqr function. How do I take the absolute value of the result. Could you show me please.
Thanks
Nick
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:nickclaridge
ID: 8205494
No that line should not produce a negative value but it still produces a run-time 5 error. Do you know why? The value produced by 1 - ((dblOrigWaveLength / 0.04572) ^ 2)) is less than 1.
0
 
LVL 1

Expert Comment

by:timd_jones
ID: 8205535
Abs(1 - ((dblOrigWaveLength / 0.04572) ^ 2)))

Less than 1 shouldn't matter.
0
 

Author Comment

by:nickclaridge
ID: 8205572
Hi again. If the rin-time error 5 is produced its not because its square rooting a negative number.
0
 
LVL 1

Expert Comment

by:timd_jones
ID: 8205577
What values are you using for AMPLITUDE and GHZFactor? Is there a specific range you are restricting the scroll bar scrGunDiode to?
0
 
LVL 1

Expert Comment

by:timd_jones
ID: 8205751
What values are you using for AMPLITUDE and GHZFactor? Is there a specific range you are restricting the scroll bar scrGunDiode to?
0
 
LVL 1

Expert Comment

by:timd_jones
ID: 8205900
The line should end up looking like this:

ComputeWaveGuideWavelength = dblOrigWaveLength / Sqr(Abs(1 - ((dblOrigWaveLength / 0.04572) ^ 2)))
0
 

Author Comment

by:nickclaridge
ID: 8206229
The scroll bar is restricted to values between 8 * 10^9 and 12 * 10^9. It should never produce a value less than 1.
0
 
LVL 6

Expert Comment

by:GPrentice00
ID: 8206232
if you are absolutely sure that the sqrt argument is SUPPOSED to be between 0 and 1, then make sure that you're using the right constant UNITS in your expression.

Remember that your units for wavelength here is mm, and make sure that constant isn't for meters, if it is, convert it.

The fact that I can get a positive number for the expression if I multiply the originalwavelength by 1000 suggests that the millimeter/meter effect is in play...




0
 
LVL 6

Expert Comment

by:GPrentice00
ID: 8206258
and technically, your scroll bar is limited between 8*GHZfactor and 12*GHZFactor (ie 800 and 1200) and your values from it converted into GHz frequencies in the calculations...

In case thats coming into play...
0
 
LVL 6

Expert Comment

by:GPrentice00
ID: 8206320
I meant divided by 1000
0
 

Author Comment

by:nickclaridge
ID: 8206385
Should the scroll bar used to change the original wavelength use the same variable name in both parts of code? i.e.scrGunDiode.Value? This is the initial value of the frequency. Should this be tied into the second snippet of code? I hope this makes sense. Is it this that is causing the run-time 5 error?
0
 

Author Comment

by:nickclaridge
ID: 8206441
If I put in the line with the Abs() function it doesn't draw a wave at all but a series of dots on the graph.
0
 
LVL 6

Accepted Solution

by:
GPrentice00 earned 320 total points
ID: 8206584
Nick

I had planned to make the code before more generic, allowing for plotting multiple waves.  And because you were refering to making computations on those waves, I've included a phase component too.

I posted a new code in your most recent PAQ for you, taking this code a step further.  I put in the 1000 factor correction hoping that that was correct, as it does do something...

0
 

Author Comment

by:nickclaridge
ID: 8206625
GPrentice00,
Thanks for that. So it will allow me to display the waveguide wavelength in the picture box....is that right. i'll stick it in and see what happens.

Nick
0
 

Author Comment

by:nickclaridge
ID: 8206744
Thanks again my friend. You really have been helpful. Lets hope I can get to grips with all this code you have given me.

Nick
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month13 days, 10 hours left to enroll

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question