|
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
' 0-3
RASEO_UseCountryAndAreaCodes = &H1
RASEO_SpecificNameServers = &H4
RASEO_IpHeaderCompression = &H8
'4-7
RASEO_RemoteDefaultGateway = &H10
RASEO_DisableLcpExtensions = &H20
RASEO_TerminalBeforeDial = &H40
RASEO_TerminalAfterDial = &H80
'8-11
RASEO_ModemLights = &H100
RASEO_SwCompression = &H200
RASEO_RequireEncryptedPw = &H400
RASEO_RequireMsEncryptedPw = &H800
'12-15
RASEO_RequireDataEncryption = &H1000
RASEO_NetworkLogon = &H2000
RASEO_UseLogonCredentials = &H4000
RASEO_PromoteAlternates = &H8000
'16-19
RASEO_SecureLocalFiles = &H10000
RASEO_RequireEAP = &H20000
RASEO_RequirePAP = &H40000
RASEO_RequireSPAP = &H80000
'20,21,23
RASEO_Custom = &H100000
RASEO_PreviewPhoneNumber = &H200000
RASEO_SharedPhoneNumbers = &H800000
'24-27
RASEO_PreviewUserPw = &H1000000
RASEO_PreviewDomain = &H2000000
RASEO_ShowDialingProgress = &H4000000
RASEO_RequireCHAP = &H8000000
'28-31
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 28-Nov-12 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
|
|
|
|
|
|
No. The only changes that should be made are the ones I highlighted.
Think about it - you need two arrays: one to hold the max widths for the output, one to hold the widths for the current input file. So you also need two subs to populate the two arrays. You have to get the max widths before reading through the input files.
There's a potential problem with the output - it probably does not line up. This is because when the input is split up it includes leading/trailing spaces. If so then GetOutputLine needs tweaking.
Where did colPos come from? It should be
columnPositions .
Is this one big application that concatenates a bunch of files, then outputs a file with parent-child lines? Or are these separate apps that just happen to have same/similar input files? The reason I ask is that the problems you are finding all seem to be related.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
|
This is same problem as before. You need to step through and check that all the values in the column position arrays are positive and increasing. And also that the input line is at least as long as the highest column position.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
As you said, i will checkout and let you know.
Thanks for your support
|
|
|
|