• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 371
  • Last Modified:

Using a picture box to draw a 70mm length of a 8Ghz sine wave

I have an 8Ghz sine wave and I need to draw a 70mm lentgh of this in a picture box that has axis labelled 0 - 70 mm (x-axis) and -1.5 - +1.5 (y-axis). What would be the code for such a picture box? Can anyone help....please?
0
nickclaridge
Asked:
nickclaridge
  • 2
1 Solution
 
rspahitzCommented:
I'm not sure if I'm on track with this, but how about:

Private Sub Command2_Click()
  Dim PI As Double
  Dim iWidth As Integer
  Dim iHeight As Integer
  Dim iPixel As Integer
  Dim dblSine As Double
 
  PI = 4 * Atn(1)'3.14159265358979
 
  iWidth = Picture1.ScaleWidth
  iHeight = Picture1.ScaleHeight
 
  Picture1.Cls
  Picture1.Line (0, iHeight / 2)-(iWidth, iHeight / 2), vbBlue
  For iPixel = 0 To iWidth
    dblSine = Sin(iPixel * (360 / iWidth) * PI / 180)
    Picture1.PSet (iPixel, iHeight / 2 - dblSine * iHeight / 2), vbRed
  Next iPixel
End Sub

The 70mm and -1.5/+1.5 numbers will merely be labels since all sine waves are the same.
0
 
nickclaridgeAuthor Commented:
Hi. This helps for the drawing of the sine wave but how would I draw an 8Ghz wave in this box???
0
 
GPrentice00Commented:
See your other message for comments on this, but I've added a bit of code to the above code to demonstrate multiwaves in a box if thats what your after.

Its not a well-written code, and I haven't factored in the actual real wavelength scale changes, but its an easy add-in modification to add to this example provided by rspahitz that can show you a demo, if thats what you want or if its not the idea.

' Add a hscroll bar and a lable1 to the example form.

' Scalefactor will determine how many sine waves to draw in the box...
' WindowwaveFixed10 says how many waves to fit in the window for 10Ghz
' GHZscalefactor is used to get finer intervals on the scrollbar.
Public ScaleFactor As Single
 Const WindowWaveFixed10 As Integer = 5
 Const GHZscalefactor As Integer = 100


Private Sub Form_Load()
' disable the scroll bar to program changes into it
' scale from 8.00 ghz to 12.00ghz
' set at 10 ghz
   HScroll1.Enabled = False
   HScroll1.Min = 8 * GHZscalefactor
   HScroll1.Max = 12 * GHZscalefactor
   HScroll1.Value = 10 * GHZscalefactor
   HScroll1.LargeChange = GHZscalefactor
   HScroll1.Enabled = True
   
End Sub

Private Sub HScroll1_Change()
   ScaleFactor = 10 * (WindowWaveFixed10) * GHZscalefactor / (HScroll1.Value)
   Label1.Caption = CStr(Val(HScroll1.Value / GHZscalefactor)) & " GHz"
   Command2_Click
End Sub

'
' modify the dblsine equation to be...
' ...Sin(iPixel * ScaleFactor * (360...
0
 
nickclaridgeAuthor Commented:
This is great thanks. It works!!!! I think I should be able to modify it for my needs. If not I'll post another question.
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now