
I'm looking for some help with computing values of a triangle and then drawing it to screen
Known;
Two points in degrees exist on a circle
Two line lengths representing ;
base, adjacent side (a)
and
opposite (c)
we want to derive side (b) hypotenuse
and also angles (A), (B), (C)
We already know that sides (a) and (c) join and we know that the longest side length will not exceed the diameter of the circle that the triangle is circumscribed within
The triangle created will be variable as different degrees and side lengths are entered, typically this will be scalene triangles but the may also be at times right triangles
I've been using a derived arc cos function ;

Public Function Arccos(X As Double) As Double
Arccos = Atn(X / Sqr(X * X + 1)) + 2 * Atn(1)
End Function

I know we can convert degrees to radians via "* Pi) / 180"
I know I can get the hypotenuse by;

side_b_squared = CDbl(c1 ^ 2 + a1 ^ 2  (c1 * a1)) * Cos(angle_B_degree_value_radians)
b1 = Sqr(side_b_squared)

I know we can get the angles A,B,C via ;

angle_C_cos_value = CDbl(a1 ^ 2 + b1 ^ 2  c1 ^ 2) / (2 * (a1 * b1))
angle_B_cos_value = CDbl(c1 ^ 2 + a1 ^ 2  b1 ^ 2) / (2 * (c1 * a1))
angle_A_cos_value = CDbl(b1 ^ 2 + c1 ^ 2  a1 ^ 2) / (2 * (b1 * c1))
angle_C_acos_value = (Arccos(angle_C_cos_value))
angle_B_acos_value = (Arccos(angle_B_cos_value))
angle_A_acos_value = (Arccos(angle_A_cos_value))
angle_C_degree_value = angle_C_acos_value * 180 / Pi
angle_B_degree_value = angle_B_acos_value * 180 / Pi
angle_A_degree_value = angle_A_acos_value * 180 / Pi

Although, I've had some trouble with this since some of the returned angles for some previous testing I did didn't
seem to be working very well, for instance I'd enter 60 degrees for angle (B) but it would somehow crunch it to
angle_B_Degree Value 38.8700377933938
I'm a little stuck on the math for all this.... here is an example scenario that I hope illustrates really clearly what I'm trying to do ;
A small VB app does the following ;
A small circle is drawn to the screen
On the form of the VB app there are text boxes that accept inputs ;
Text 1 = side (c) length as a number
Text 2 = side (a) length as a number
Text 3 = a value in degrees that represents a point of one of the ends of side (c)
Text 4 = a value in degrees that represents a point of one of the ends of side (a)
Then the following are computed ;
side length of the hypotenuse as a number, and output to a different text box
Angles (A), (B), (C) are computed as values in degrees, and output to another text box
The drawn circle may be say four inches in diameter, and all side lengths computed, regardless of their number value
are fit proprotionally, circumscribed within the circle, so even if one of the side lengths is really long, all side lengths are fit proportionally in the circle but retaining the same intrinsic unit measure values of their lengths.
Any help or insights on the above are really appreciated, especially the math and formula end and any code ideas, samples are a God send.
I'm a bit of a newbie with all this and I'm using an older version of VB (4.0)
I have a basic idea on using some of the draw functions and I think I can tinker my way through this, but again am very open to any feedback
Thanks people!





It would help if you stopped using the term Hypotenuse, as this only applies to Right Angles.
Also, is the radius known or unknown?

"Children today are tyrants. They contradict their parents, gobble their food and tyrannize their teachers. I despair for the future."
Socrates 400BC





Ok, will stop using the term hypotenuse!
Also, the longest triangle side will never exceed the diameter of the circle, but here are some more notes that may be helpful in better understanding what I'm trying to do ;
The triangle, circumscribed within the circle is situated so that each point of the triangle must fall somewhere on the perimeter of the circle itself For example sides 'a' and 'b' both have one of their ends at the centerpoint of the circle, and the angle between them is angle 'C'
What Im hoping for here, is that the circle centerpoint is not used at all, so no ends of the triangle will everland there
There needs to be actually four inputs... I know this sounds a bit unorthodox, but here is the interesting part of the problem... I'll clarify this.....
We want two inputs that store the lengths of two of the sides of the triangle ;
Text 1 = side (c) length as a number
Text 2 = side (a) length as a number
We also want two inputs that store two values that are points on the perimeter of the circle in degrees
Text 3 = a value in degrees that represents a point of one of the ends of side (c)
Text 4 = a value in degrees that represents a point of one of the ends of side (a)
So in the end we know that we have two sides of specific lengths that must fit within the circle, and we know that one of the ends of each line is connected to a specific degree point on that circle, we also know that both these side lengths do join somehow somewhere, but the degrees that are input ARE NOT the angles of any part of the triangle, here in this case, the degrees that are input are ONLY points on the circle itself that are simply where the lines of each respective triangle, so for example
A circle of four inches diameter
a line length of 10 units has one end point at 30 degrees
a second line length of 8 units has its end point at say, 78 degrees
where does the third point fall on the circles perimeter? at what degree?
what is the line length of the missing side, and then what are the angles contained within the triangle....
This is the math, code part I am hoping for help on..... I hope this clarifies?
Also... I'm using VB 4.0 and can't upgrade for a while  long story





Rockoon!
Thank you so much for your reply!
I just realized I made an assumption that may not be correct at all.
I had thought earlier that if we knew two points in degrees on the circle, then the difference or sum between them must be either one of the values of the unknown internal angle, or at least it would represent the other 3rd unknown point on the circle.
Now I'm thinking that, thats just a poor guess on my part!
Although, I then realized that if we knew two of the lengths of two of the sides, and if we knew that each line was associated with one of the points, then one of the lines must also intersect the two known points, and since that is the case then if the line that joins the two points is not equal to either of the two known line lengths then that gives us the missing side!?
If thats the case then its a matter of deriving where the third unknown point in degrees on the circle would be where the two known line lengths would meet?
I'm guessing, but if I'm not mistaken there could only be a maximum of two specific points on the circle where these two lines could join? But maybe only one place?
I'm hoping there is a way to 'algebratize' all this and then code it!?
Also, this is really important I feel ;
The lines of the triangle will be variable and in generic units, but say we know that the diameter of the circle is four inches. Line lengths may be values of 10, 23, 5, what ever... but they will fit proportionately in the circle, so the lines of generic unit measure need to be fit within the circle.
Here, we only know two of the points on the circle
In this exercise we don't know any of the internal angles, all we know are two points in degrees on the circle (the third is unknown) and we know that each point will be associate with one of the two known line lengths
We have the following unknowns;
All three internal angles, and one of the side lengths
All we know is two side lengths, two points on the circle in degrees where each point is associated with one of the side lengths, and we know which point on the circle is associate with which line,
We also know that the two known points on the circle must join and that this line may or may not be one of the known lines. Some sort of check, if statement could verify it when measured proprtionately somehow and if its not one of the known line lengths then we have our third unknown line





If you only know two side lengths of a scalene triangle (but none of the angles) can you determine the third side length?
I had been using this formula to determine the length of the hypotenuse ;
SQRT ( side1^2 + side2^2)
But realized that this is meant ONLY to determine the side length of the hypotenuse for right triangles and not scalenes per se.... is there some other formla that can be used to get the line length of the hypotenuse for a scalene in the above situation?
If there isn't a way to get the 3rd line length of scalenes this way, do you know if there is a way to get the hypotenuse line length AND the angle between the hypotenuse and the base, if we have the two side lengths of the base(adjacent) and the opposite side, and if we have the associated angles for these sides?
I've tried to incorporate all I've learned so far... but I keep getting weird errors and as far as I can tell all my formulas are correct?
I've built a small VB program, am including a sample below and the critical formulas and code I'm using... if any one can shed some light on where I've gone wrong it would be so nice!
( I'm using VB 4.0 and can't upgrade right now so I have to work within that limitation)
Here is an example ;
Accept input from three text entry boxes
1.) Value for Side (a), Adjacent Base
the value of 14 is entered
2.) Value for Side (c), Opposite
the value of 10 is entered
3.) Angle (B) [ entered as degrees ]
the value of 60 degrees is entered
The hypotenuse is computed to be ;
8.83176086632785
The arc cos function is derived ;
Public Function Arccos(X As Double) As Double
Arccos = Atn(X / Sqr(X * X + 1)) + 2 * Atn(1)
End Function
Its then called from code below
Pi is declared as a constant in a module
'=======================
'=======================
'Converts the entry from degrees to radians
angle_B_degree_value_radians = (angle_B_degree_value * Pi) / 180
'get hypotenuse side length and outputs it to a text box
side_b_squared = CDbl(c1 ^ 2 + a1 ^ 2  (c1 * a1)) * Cos(angle_B_degree_value_radians)
b1 = Sqr(side_b_squared)
Text5.Text = b1
angle_C_cos_value = CDbl(a1 ^ 2 + b1 ^ 2  c1 ^ 2) / (2 * (a1 * b1))
angle_B_cos_value = CDbl(c1 ^ 2 + a1 ^ 2  b1 ^ 2) / (2 * (c1 * a1))
angle_A_cos_value = CDbl(b1 ^ 2 + c1 ^ 2  a1 ^ 2) / (2 * (b1 * c1))
angle_C_acos_value = (Arccos(angle_C_cos_value))
angle_B_acos_value = (Arccos(angle_B_cos_value))
angle_A_acos_value = (Arccos(angle_A_cos_value))
angle_C_degree_value = angle_C_acos_value * 180 / Pi
angle_B_degree_value = angle_B_acos_value * 180 / Pi
angle_A_degree_value = angle_A_acos_value * 180 / Pi
'=======================
'=======================
The problem is, that
angle_B_Degree Value 38.8700377933938
is returned as a degree value very different from what I entered ( 60 ) degrees! I wanted to recompute this angle to confirm that it was working ok.... but it seems often off, so now I dont know how valid any of my calculations are! I don't understand why this is happening?
I've also tried entering angles different from 60 degrees but with the samed side length values, for instance if I enter 90 degrees or 120 degrees it jus automatically fails.... if I enter 80 degrees I also get an error back....?





Without angles, no.
There is a maximum length for the third side, which is the sum of the lengths of the other 2 sides.
Imagine a pair of compasses, the length of the two legs is fixed, but the third length can be changed bu pushing them apart or pulling them together, so length of two sides does not give length of third.
Euclidian Geometry and Pythagorean Maths are a pain yes?

"Children today are tyrants. They contradict their parents, gobble their food and tyrannize their teachers. I despair for the future."
Socrates 400BC






Without knowing the angle between the two known sides, either directly or computed by other means, it's impossible to determine the length of the third side.





How could I display font in a combo1 (and size in combo2) showing them the font and size of the richtextbox (rtfText) on the cursor position basis?
They already show fonts and sizes existing in the system font, but I should want to add code to show which font and which size is running moving cursor all aroung the text.
On form_load I have
Dim i As Integer
' Declares an integer 'i' for the multiple purposes
' User selects the font size from this combo box
For i = 8 To 12
cboSize.AddItem i
Next i
For i = 1 To Screen.FontCount  1
If Screen.Fonts(i) <> "" Then cboFont.AddItem Screen.Fonts(i)
Next i
BUT NOW? Thanks in advance.





Your question isn't very clear at all. Are you asking how to set the font at the cursor position or change the font of the selected text in a RichTextBox??





You need to write a handler for the change event of the RTFTextbox. There you read the current font properties and update your selected items in your comboboxes accordingly. If it slows down your app too much you can try to use a timer control, to loosen the coupling of updating the comboboxes and the movement of the cursor.
Regards: Didi





I need to write debug outputs and general log file data to a log file.
There may be several instances of the application that needs to write this data running at the same time, processing different data sets. I need to collect the outputs into a single shared log file that will be appended to.
I thought that the simple way would be for each instance to create a logfile with a unique name, then when the application is done, it would spool the content of it's own unique log file to a system printer that used the FILE driver. In this way I thought I could avoid writing a spooler of my own.
The problem that I haven't yet overcome is that the print to file driver pops up a window asking for the output file name each time it is called. I'm not sure whether the shared/spooled write access I seek will work even after I get past this problem.
There may be a much simpler way to do what I am trying to do, but I haven't found it yet.
For an ancient assembler/Fortran coder like me learning how to use the extreme richness of VB 2008 reminds me of an old text based dungeons and dragons game.





So what's wrong with just every instance of the app writing to the same log file?? It's easy enough to pull off. Just open the file, write the message, and close the file. But, there's a little catch. Keep attempting to open the file DenyShareAll until it actually opens. It shouldn't take very long at all if your messages are short.
Another possibility is a service or other server app that listens for messages comming from your app. All instances of the app talk to the same instance of the loggin component, that itself writes to the log.
Using the print FILE driver is a bit too much for such a simple operation.





Thanks for the help Dave. I adapted the DenyShareAll methodology  I'm using a Streamwriter to send the text to the file and I couldn't find a DenyShareAll property for it so I'm simply catching the IOEXCEPTION when it tries to open the file, waiting 500 ms and trying again till I get access. Seems to work so far.
I'd prefer the inter process comms model (as a purist) but I didn't feel like learning how to use named pipes or some similarly complex substitute today. Maybe tomorrow





Roy Barkas wrote: I'm using a Streamwriter to send the text to the file and I couldn't find a DenyShareAll property for it so I'm simply catching the IOEXCEPTION when it tries to open the file, waiting 500 ms and trying again till I get access. Seems to work so far.
That's how you're supposed to do it!
Roy Barkas wrote: I'd prefer the inter process comms model (as a purist) but I didn't feel like learning how to use named pipes or some similarly complex substitute today. Maybe tomorrow
That's how I learned how to do this stuff. Just write little examples that do nothing but what I need.





Hi all,
i am fetching float value from SQL
select instanceid2400,CAST(weight as float) as GrossWeight from .....
but when i am reading it
Private Sub Fetch(ByVal dr As SafeDataReader)
'Load object data from the Database
With dr
_GrossWeight = .GetDouble("GrossWeight")
where _GrossWeight has also datatype as double
it's not working fine
similarly when i change my query to
select instanceid2400,CAST(weight as int) as GrossWeight from .....
_GrossWeight = .Getint32("GrossWeight")
it works fine
what can be the solution
Ankit Aneja
"Nothing is impossible. The word itself says  I M possible"





Ankit Aneja wrote: With dr
_GrossWeight = .GetDouble("GrossWeight")
where _GrossWeight has also datatype as double
it's not working fine
So what IS the result?? Are you getting a value?? What is the expected value and what is the actual value returned?? Is there an error message??





just closed my editor and opened again it wrks
something strange i din't get
Thanks a lot
Ankit Aneja
"Nothing is impossible. The word itself says  I M possible"





Hi all
I want to create a RAS(PPTP) entry without "Require data encryption(disconnect if none)", below is my code. I have tried several times, but the option "RASEO_RequireDataEncryption" seems not work. But other option such as "RASEO_RemoteDefaultGateway" works fine. Can someone help? Thanks in advance!

Enum RasEntryOptions
' 03
RASEO_UseCountryAndAreaCodes = &H1
RASEO_SpecificNameServers = &H4
RASEO_IpHeaderCompression = &H8
'47
RASEO_RemoteDefaultGateway = &H10
RASEO_DisableLcpExtensions = &H20
RASEO_TerminalBeforeDial = &H40
RASEO_TerminalAfterDial = &H80
'811
RASEO_ModemLights = &H100
RASEO_SwCompression = &H200
RASEO_RequireEncryptedPw = &H400
RASEO_RequireMsEncryptedPw = &H800
'1215
RASEO_RequireDataEncryption = &H1000
RASEO_NetworkLogon = &H2000
RASEO_UseLogonCredentials = &H4000
RASEO_PromoteAlternates = &H8000
'1619
RASEO_SecureLocalFiles = &H10000
RASEO_RequireEAP = &H20000
RASEO_RequirePAP = &H40000
RASEO_RequireSPAP = &H80000
'20,21,23
RASEO_Custom = &H100000
RASEO_PreviewPhoneNumber = &H200000
RASEO_SharedPhoneNumbers = &H800000
'2427
RASEO_PreviewUserPw = &H1000000
RASEO_PreviewDomain = &H2000000
RASEO_ShowDialingProgress = &H4000000
RASEO_RequireCHAP = &H8000000
'2831
RASEO_RequireMsCHAP = &H10000000
RASEO_RequireMsCHAP2 = &H20000000
RASEO_RequireW95MSCHAP = &H40000000
RASEO_CustomScript = &H80000000
End Enum
Function CreateNewEntry(ByVal sUsername As String, ByVal sPassword As String, ByVal sIP As String) As Boolean
CreateNewEntry = False
Dim re As RASENTRY
Dim sDeviceName As String ', sDeviceType As String
sDeviceName = "WAN Miniport(PPTP)"
With re
.dwSize = LenB(re)
.dwCountryCode = 86
.dwCountryID = 86
.dwDialExtraPercent = 75
.dwDialExtraSampleSeconds = 120
.dwDialMode = 1
.dwEncryptionType = 3
.dwfNetProtocols = 4
.dwfOptions = RASEO_RequireDataEncryption + RASEO_RemoteDefaultGateway
.dwFramingProtocol = 1
.dwHangUpExtraPercent = 10
.dwHangUpExtraSampleSeconds = 120
.dwRedialCount = 3
.dwRedialPause = 3
.dwVpnStrategy = VS_PptpOnly
.dwType = 5
CopyMemory .szLocalPhoneNumber(0), ByVal sIP, Len(sIP)
CopyMemory .szDeviceName(0), ByVal sDeviceName, Len(sDeviceName)
CopyMemory .szDeviceType(0), ByVal sDeviceType, Len(sDeviceType)
End With
Dim rc As RASCREDENTIALS
With rc
.dwSize = LenB(rc)
.dwMask = 11
CopyMemory .szUserName(0), ByVal sUsername, Len(sUsername)
CopyMemory .szPassword(0), ByVal sPassword, Len(sPassword)
End With
Dim rtn As Long
If RasSetEntryProperties(vbNullString, sEntryName, re, LenB(re), 0, 0) = 0 Then
If RasSetCredentials(vbNullString, sEntryName, rc, 0) = 0 Then
CreateNewEntry = True
End If
End If
End Function





The only obvious thing that jumps out is the re.dwfOptions need to be Or'd together, not added.
Other than that, you're treading in very rare territory. It's unlikely you're going to find anyone who has experience using the RAS library.





Thanks in advance.
modified 28Nov12 8:14am.





Soooooo, what in these headers is going to tell you the field length??





I knew this was going to be a problem.
Is there not some specification somewhere that tells you the layout of the files? Why are they different?
Regards
David R

"Every program eventually becomes rococo, and then rubble."  Alan Perlis





Here's a possible solution assuming you want to do it in AppendFiles(). Check the names in GetMaxColPos I'm not sure they're correct.
Private Sub AppendFiles(ByVal inputPath As String, ByVal outputFile As String)
Dim columnPositions(10) As Integer
Dim theDir As DirectoryInfo = New DirectoryInfo(inputPath)
Dim theFiles As FileInfo() = theDir.GetFiles("*.txt")
Dim doHeaders As Boolean = Not File.Exists(outputFile)
Dim maxColPos(10) As Integer
Call GetMaxColPos(maxColPos, theFiles)
Using sw As StreamWriter = New StreamWriter(outputFile, True, System.Text.Encoding.Default)
.......
'Now read and write the data lines
While sr.Peek() >= 0
inputLine = sr.ReadLine()
outputLine = GetOutputLine(inputLine, createdAt, maxColPos)
sw.WriteLine(outputLine)
End While
End Using
Next fileCount
End Using
End Sub
Private Sub GetMaxColPos(ByVal p As Integer(), ByVal files As FileInfo())
Dim inLine As String
Dim fieldLen As Integer
For Each fi As FileInfo In files
Using sr As StreamReader = New StreamReader(fi.FullName(), System.Text.Encoding.Default)
inLine = sr.ReadLine()
fieldLen = inLine.IndexOf("Nom du Modèle")
If (fieldLen > p(0)) Then p(0) = fieldLen
fieldLen = inLine.IndexOf("AEC_COMPATIBILITY")
If (fieldLen > p(1)) Then p(1) = fieldLen
fieldLen = inLine.IndexOf("AEC_STANDARD_DESCRIPTION_FRENCH")
If (fieldLen > p(2)) Then p(2) = fieldLen
fieldLen = inLine.IndexOf("AEC_FREE_DESCRIPTION_FRENCH")
If (fieldLen > p(3)) Then p(3) = fieldLen
fieldLen = inLine.IndexOf("AWW_STANDARD_DESCRIPTION")
If (fieldLen > p(4)) Then p(4) = fieldLen
fieldLen = inLine.IndexOf("AEC_FREE_DESCRIPTION_ENGLISH")
If (fieldLen > p(5)) Then p(5) = fieldLen
fieldLen = inLine.IndexOf("AEC_ECN")
If (fieldLen > p(6)) Then p(6) = fieldLen
fieldLen = inLine.IndexOf("DNF")
If (fieldLen > p(7)) Then p(7) = fieldLen
fieldLen = inLine.IndexOf("REP_DNF")
If (fieldLen > p(8)) Then p(8) = fieldLen
fieldLen = inLine.IndexOf("REP_ASM")
If (fieldLen > p(9)) Then p(9) = fieldLen
End Using
Next
End Sub
Regards
David R

"Every program eventually becomes rococo, and then rubble."  Alan Perlis





