Imports System.Math Imports System.Char Public Class Acceuil Public Structure CodeSexa Dim Degrés As Integer Dim Minutes As Integer Dim Secondes As Integer End Structure 'Définition des variables Private AngD As Double Private AngS As CodeSexa 'Algorithmes Private Function SexaVersDéci(ByVal Sex As CodeSexa) As Double Dim Déc As Double With Sex Déc = .Degrés + .Minutes / 60 + .Secondes / 3600 End With Return Déc End Function Private Function DéciVersSexa(ByVal Déc As Double) As CodeSexa Dim Sex As CodeSexa, Sec As Integer, Q As Integer Sec = CInt(3600 * Déc) With Sex Q = DivRem(Sec, 60, .Secondes) .Degrés = DivRem(Q, 60, .Minutes) End With Return Sex End Function 'Formatages ''' <summary> ''' Retourne le texte représentant le réel x avec quatre décimales. ''' </summary> Private Function Formaté(ByVal x As Double) As String Return x.ToString("0.0000").Replace(".", ",") End Function ''' <summary> ''' Retourne le texte représentant l'entier x avec au moins n chiffes. ''' </summary> Private Function Formaté(ByVal x As Integer, ByVal n As Integer) As String Dim c As Char = Parse("0"), t As New String(c, n) Return x.ToString(t) End Function 'Textes Private Function TexteDéci(ByVal Sex As CodeSexa) As String Return Formaté(SexaVersDéci(Sex)) End Function Private Function TexteSexa(ByVal Déc As Double) As String Dim Sex As CodeSexa = DéciVersSexa(Déc) Dim Txt As String With Sex Txt = Formaté(.Degrés, 1) & "°" ' & Formaté(.Minutes, 2) & Formaté(.Secondes, 2) Txt = Txt & Formaté(.Minutes, 2) & "'" Txt = Txt & Formaté(.Secondes, 2) & """" End With Return Txt End Function 'Tests Private Sub TesterSexaVersDéci() With AngS .Degrés = 10 .Minutes = 30 .Secondes = 9 End With MessageBox.Show(TexteDéci(AngS)) End Sub Private Sub TesterDéciVersSexa() AngD = 10.5025 MessageBox.Show(TexteSexa(AngD)) End Sub End Class
Private Sub TextBox1_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox1.TextChanged TextBox2.Text = "Ton texte" End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionReturn gps_sexa Calcul()
Va dans la maison, fais ça
Ensuite sort de la maison et va dans la salle de bain et fais ça
Va dans la maison, fais ça
Ensuite va dans la salle de bain, fais ça puis ensuite sort de la maison
Calcul() Return gps_sexa
Je sais, pas très bon comme exemple mais j'ai que ça sous le coude !
Imports System.Math Public Class Acceuil Public Structure CodeSexa Dim Degrés As Integer Dim Minutes As Integer Dim Secondes As Integer End Structure 'Définition des variables Private AngD As Double Private AngS As CodeSexa 'Algorithmes Private Function SexaVersDéci(ByVal Sex As CodeSexa) As Double Dim Déc As Double With Sex Déc = .Degrés + .Minutes / 60 + .Secondes / 3600 End With Return Déc End Function Private Function DéciVersSexa(ByVal Déc As Double) As CodeSexa Dim Sex As CodeSexa, Sec As Integer, Q As Integer Sec = CInt(3600 * Déc) With Sex Q = DivRem(Sec, 60, .Secondes) .Degrés = DivRem(Q, 60, .Minutes) End With Return Sex End Function 'Tests Private Sub TesterSexaVersDéci() With AngS .Degrés = 10 .Minutes = 30 .Secondes = 9 End With AngD = SexaVersDéci(AngS) MessageBox.Show(AngD.ToString) End Sub Private Sub TesterDéciVersSexa() Dim Msg As String AngD = 10.5025 AngS = DéciVersSexa(AngD) With AngS Msg = .Degrés.ToString & "°" & .Minutes.ToString & "'" & .Secondes.ToString & """" End With MessageBox.Show(Msg) End Sub End Class
Imports System.Math Public Class GPS ' ******************* base 60 2 Deci ****************************** 'Exemple. Soit une latitude de 45° 53' 36" (45 degrés, 53 minutes et 36 secondes). 'Exprimée en degrés décimaux, la latitude sera égale à : 'latitude 45 + (53 / 60) + (36 / 3600) 45,89 'Formulation générale : 'latitude (degrés décimaux) = degrés + (minutes / 60) + (secondes / 3600) ' ******************* decimal 2 base 60 ************************** 'Exemple : soit une longitude de 121,135° ' 'Le nombre avant la virgule indique les degrés ? 121° 'Multiplier le nombre après la virgule par 60 ? 0,135 * 60 = 8,1 'Le nombre avant la virgule devient la minute (8') 'Multiplier le nombre après la virgule par 60 ? 0,1 * 60 = 6 'Le résultat correspond aux secondes (6"). 'Notre longitude sera de 121° 8' 6" Dim LblTitre As New Label With {.Parent = Me, _ .Location = New Point(0, 0), _ .Size = New System.Drawing.Size(342, 48), _ .Text = "Conversion GPS", _ .Font = New System.Drawing.Font("Microsoft Sans Serif", _ 20.25!, System.Drawing.FontStyle.Bold, _ System.Drawing.GraphicsUnit.Point, CType(0, Byte)), _ .ForeColor = System.Drawing.Color.Blue, _ .BackColor = System.Drawing.Color.Yellow} Dim LblBase60 As New Label With {.Parent = Me, _ .Location = New Point(20, 80), _ .Text = "Deg Min Sec"} Dim LblDeci As New Label With {.Parent = Me, _ .Location = New Point(20, 125), _ .Text = "Decimal"} Dim WithEvents TxtSexa As New TextBox With {.Parent = Me, _ .Location = New Point(120, 80), _ .Text = "00 00 00", _ .Font = New System.Drawing.Font _ ("Microsoft Sans Serif", 14.0!, _ System.Drawing.FontStyle.Bold, _ System.Drawing.GraphicsUnit.Point, _ CType(0, String))} Dim WithEvents TxtDecimal As New TextBox With {.Parent = Me, _ .Location = New Point(120, 115), _ .Text = "00,0000", _ .Font = New System.Drawing.Font _ ("Microsoft Sans Serif", 14.0!, _ System.Drawing.FontStyle.Bold, _ System.Drawing.GraphicsUnit.Point, _ CType(0, String))} Public Structure CodeSexa Dim Degrés As Integer Dim Minutes As Integer Dim Secondes As Integer End Structure 'Définition des variables Private AngD As Double Private AngS As CodeSexa 'Algorithmes Public Function SexaVersDéci(ByVal Sex As CodeSexa) As Double Dim Déc As Double With Sex Déc = .Degrés + .Minutes / 60 + .Secondes / 3600 End With Return Déc End Function Public Function DéciVersSexa(ByVal Déc As Double) As CodeSexa Dim Sex As CodeSexa, Sec As Integer, Q As Integer Sec = CInt(3600 * Déc) With Sex Q = DivRem(Sec, 60, .Secondes) .Degrés = DivRem(Q, 60, .Minutes) End With Return Sex End Function Private Sub Txt_Sexa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles TxtSexa.Click If TxtSexa.Text <> "00 00 00" Then With AngS If Microsoft.VisualBasic.Left(TxtSexa.Text, 2) = "" Then .Degrés = "00" Else .Degrés = Microsoft.VisualBasic.Left(TxtSexa.Text, 2) End If If Microsoft.VisualBasic.Mid(TxtSexa.Text, 4, 2) = "" Then .Minutes = "00" Else .Minutes = Microsoft.VisualBasic.Mid(TxtSexa.Text, 4, 2) End If If Microsoft.VisualBasic.Right(TxtSexa.Text, 2) = "" Then .Secondes = "00" Else .Secondes = Microsoft.VisualBasic.Right(TxtSexa.Text, 2) End If End With TxtDecimal.Text = SexaVersDéci(AngS) End If End Sub Private Sub TxtDecimal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles TxtDecimal.Click If TxtDecimal.Text <> "00,0000" Then Dim Résultat As String AngD = TxtDecimal.Text '10.5025 AngS = DéciVersSexa(AngD) With AngS Résultat = .Degrés.ToString & "°" & _ .Minutes.ToString & "'" & .Secondes.ToString & """" End With TxtSexa.Text = Résultat End If End Sub End Class
j'aimerais que quand j'écris dans un TextBox, ça modifie l'autre Texbox
j'aimerais aussi formater les textes dans les TextBox
Imports System.Char Public Class Accueil ''' <summary> ''' Retourne le texte représentant le réel x avec quatre décimales. ''' </summary> Private Function Formaté(ByVal x As Double) As String Return x.ToString("0.0000").Replace(".", ",") End Function ''' <summary> ''' Retourne le texte représentant l'entier x avec au moins n chiffes. ''' </summary> Private Function Formaté(ByVal x As Integer, ByVal n As Integer) As String Dim c As Char = Parse("0"), t As New String(c, n) Return x.ToString(t) End Function End Class
Imports System.Math Public Class GPS ' ******************* base 60 2 Deci ****************************** 'Exemple. Soit une latitude de 45° 53' 36" (45 degrés, 53 minutes et 36 secondes). 'Exprimée en degrés décimaux, la latitude sera égale à : 'latitude 45 + (53 / 60) + (36 / 3600) 45,89 'Formulation générale : 'latitude (degrés décimaux) = degrés + (minutes / 60) + (secondes / 3600) ' ******************* decimal 2 base 60 ************************** 'Exemple : soit une longitude de 121,135° ' 'Le nombre avant la virgule indique les degrés ? 121° 'Multiplier le nombre après la virgule par 60 ? 0,135 * 60 = 8,1 'Le nombre avant la virgule devient la minute (8') 'Multiplier le nombre après la virgule par 60 ? 0,1 * 60 = 6 'Le résultat correspond aux secondes (6"). 'Notre longitude sera de 121° 8' 6" Dim LblTitre As New Label With {.Parent Me, .Location New Point(0, 0), .Size = New System.Drawing.Size(342, 48), .Text = "Conversion GPS", _ .Font = New System.Drawing.Font("Microsoft Sans Serif",20.25!, System.Drawing.FontStyle.Bold, _ System.Drawing.GraphicsUnit.Point, CType(0, Byte)), .ForeColor = System.Drawing.Color.Blue, _ .BackColor = System.Drawing.Color.Yellow} Dim LblBase60 As New Label With {.Parent Me, .Location New Point(20, 80), .Text = "Deg Min Sec"} Dim LblDeci As New Label With {.Parent Me, .Location New Point(20, 125),.Text = "Decimal"} Dim WithEvents TxtDegre As New TextBox With {.Parent Me, .Location New Point(120, 80), .Size = New Point(40, 20), .Text = "", _ .Font = New System.Drawing.Font("Microsoft Sans Serif", 14.0!, System.Drawing.FontStyle.Bold, _ System.Drawing.GraphicsUnit.Point, CType(0, String))} Dim WithEvents TxtMinute As New TextBox With {.Parent Me, .Location New Point(162, 80), .Size = New Point(35, 20), .Text = "", _ .Font = New System.Drawing.Font("Microsoft Sans Serif", 14.0!, System.Drawing.FontStyle.Bold, _ System.Drawing.GraphicsUnit.Point, CType(0, String))} Dim WithEvents TxtSeconde As New TextBox With {.Parent Me, .Location New Point(200, 80), .Size = New Point(35, 20), .Text = "", _ .Font = New System.Drawing.Font("Microsoft Sans Serif", 14.0!, System.Drawing.FontStyle.Bold, _ System.Drawing.GraphicsUnit.Point, CType(0, String))} Dim WithEvents TxtDecimal As New TextBox With {.Parent Me, .Location New Point(120, 115), .Text = "", .Size = New Point(115, 115), _ .Font = New System.Drawing.Font("Microsoft Sans Serif", 14.0!, System.Drawing.FontStyle.Bold, _ System.Drawing.GraphicsUnit.Point, CType(0, String))} Dim WithEvents BtnConvertir As New Button With {.Parent Me, .Location New Point(100, 200), .Text = "Convertir"} Public Structure CodeSexa Dim Degrés As Integer Dim Minutes As Integer Dim Secondes As Integer End Structure 'Définition des variables Private AngD As Double Private AngS As CodeSexa 'Algorithmes Public Function SexaVersDéci(ByVal Sex As CodeSexa) As Double Dim Déc As Double With Sex Déc = .Degrés + .Minutes / 60 + .Secondes / 3600 End With Return Déc End Function Public Function DéciVersSexa(ByVal Déc As Double) As CodeSexa Dim Sex As CodeSexa, Sec As Integer, Q As Integer Sec = CInt(3600 * Déc) With Sex Q = DivRem(Sec, 60, .Secondes) .Degrés = DivRem(Q, 60, .Minutes) End With Return Sex End Function Sub BtnConvertir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnConvertir.Click If TxtDegre.Text <> "" Then With AngS .Degrés = TxtDegre.Text If TxtMinute.Text <> "" Then .Minutes = TxtMinute.Text End If If TxtSeconde.Text <> "" Then .Secondes = TxtSeconde.Text End If End With TxtDecimal.Text = SexaVersDéci(AngS) End If If TxtDecimal.Text <> "" Then AngD = TxtDecimal.Text AngS = DéciVersSexa(AngD) With AngS TxtDegre.Text = .Degrés.ToString TxtMinute.Text = .Minutes.ToString TxtSeconde.Text = .Secondes.ToString End With End If End Sub End Class
Préparons-nous donc à assister à la création du mouvement perpétuel.
Il n'a qu'a utiliser la propriété Focused du textbox pour savoir lequel des deux est en train d'être modifié.