Séparer caractère avec un tiret VB2008

Résolu
fallout81 Messages postés 11 Date d'inscription lundi 28 septembre 2009 Statut Membre Dernière intervention 15 mars 2012 - 13 mars 2012 à 17:20
fallout81 Messages postés 11 Date d'inscription lundi 28 septembre 2009 Statut Membre Dernière intervention 15 mars 2012 - 14 mars 2012 à 02:00
Bonjour à tous,
Je viens vous demander de l'aide car je suis dans une impasse :/
Mon projet est de faire un info pc avec les informations principales : carte graphique, processeur, ip ect... Arriver à l'adresse MAC j'ai un soucis celle ci est correcte mais je voudrais, tout les deux caractères mettre un tiret cella est t-il possible ?
ps : l'adresse mac s'affiche dans une textbox

Merci d'avance pour vos futures réponses :)

Bonne fin de journée

14 réponses

cs_ShayW Messages postés 3253 Date d'inscription jeudi 26 novembre 2009 Statut Membre Dernière intervention 3 décembre 2019 57
13 mars 2012 à 23:58
d'abord fonction améliorée

Private Function InsertChar(ByVal ch As Char, ByVal word As String, ByVal count As Integer) As String
   Dim strin As String
   Dim k As Integer
   k = 0
   strin = String.Empty
   For iter = 0 To word.Length - 1 Step count
      Try
         strin = word.Insert(iter + count + k, ch)
          word = strin
          k += 1
       Catch ex As Exception

      End Try
    Next
    Return strin
 End Function


peut etre dans le Form1_Load
'Textbox13.text = getMacAddress()
textbox13.text = InsertChar("-",getMacAddress(),2)
3
cs_ShayW Messages postés 3253 Date d'inscription jeudi 26 novembre 2009 Statut Membre Dernière intervention 3 décembre 2019 57
13 mars 2012 à 20:56
Salut

Private Function InsertChar(ByVal ch As Char, ByVal word As String, ByVal count As Integer) As String
        Dim strin As String
        Dim k As Integer
        If word.Length Mod count = 0 Then
            k = 0
        Else
            k = word.Length Mod count
        End If
        strin = String.Empty
        For iter = 0 To word.Length - 1 - k Step count
            strin &= word.Substring(iter, count) & ch
        Next
        If k = 0 Then
            Return strin.Substring(0, strin.Length - 1)
        Else
            Return strin & word.Substring(word.Length - 1 - k)
        End If

    End Function


Dim word As String
word = InsertChar("-"c, "ABCRTGTTYGTZ"
, 2)
0
fallout81 Messages postés 11 Date d'inscription lundi 28 septembre 2009 Statut Membre Dernière intervention 15 mars 2012
13 mars 2012 à 21:15
Merci de ta réponse rapide :)
j'ai inséré le code mais au niveau de
Dim word As String
word = InsertChar("-"c, "ABCRTGTTYGTZ"
, 2)
word est souligné :/ ne faut il pas mettre private function ou quelque chose du genre haut dessus ?

en tout cas merci d'avoir pris la peine de me répondre
0
cs_ShayW Messages postés 3253 Date d'inscription jeudi 26 novembre 2009 Statut Membre Dernière intervention 3 décembre 2019 57
13 mars 2012 à 21:20
c'est
Dim word As String
word = InsertChar("-"c, "ABCRTGTTYGTZ", 2)
ou pour ton cas si text1 est le textbox de MAC

word = InsertChar("-"c, text1.text, 2)
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
fallout81 Messages postés 11 Date d'inscription lundi 28 septembre 2009 Statut Membre Dernière intervention 15 mars 2012
13 mars 2012 à 21:39
toujours l'erreur :/ voila un screen pour t'aider a voir la situation

http://img29.imageshack.us/img29/2445/sanstitreqqs.png
0
ucfoutu Messages postés 18038 Date d'inscription lundi 7 décembre 2009 Statut Modérateur Dernière intervention 11 avril 2018 211
13 mars 2012 à 21:56
Bonjours.
Intervention d'un petit VBiste (pas vb.nettiste) :
Ne me dites pas que l'on ne peut pas faire avec vb.net les choses aussi simplement que ceci :
toto = "abracadabraetzbrasdevb6-basque"
If Len(toto) Mod 2 <> 0 Then toto = toto & " "
f = "@@ "
For i = 1 To Len(toto) \ 3
 f = f & " " & f
Next
MsgBox Trim(Format(toto, f))

ou alors : on vous a roulés dans la farine


____________________
Réponse exacte ? => "REPONSE ACCEPTEE" pour faciliter les recherches d'autres forumeurs.
Pas d'aide en ligne installée ? ==> ne comptez pas sur moi pour simplement vous dire ce qu'elle contient
0
cs_ShayW Messages postés 3253 Date d'inscription jeudi 26 novembre 2009 Statut Membre Dernière intervention 3 décembre 2019 57
13 mars 2012 à 21:57
Envois le code que tu as écrit
0
fallout81 Messages postés 11 Date d'inscription lundi 28 septembre 2009 Statut Membre Dernière intervention 15 mars 2012
13 mars 2012 à 22:03
Imports System.Management
Imports System.Net.NetworkInformation.NetworkInterface
Imports System.Net.NetworkInformation


Public Class Form1
    Public Overloads Shared Function VGA() As Integer




    End Function

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        WebBrowser1.Navigate("http://www.showmyip.com/simple/")

        Dim readValue As String
        TextBox1.Text = System.Environment.MachineName 'nom du PC
        TextBox2.Text = System.Environment.UserName ' nom de l'utilisateur
        TextBox3.Text = My.Computer.Info.OSFullName ' l'O.S
        TextBox4.Text = My.Computer.Info.OSPlatform ' 32 ou 64 bits
        TextBox5.Text = My.Computer.Info.OSVersion
        TextBox6.Text = My.Computer.Info.InstalledUICulture.ToString ' la langue

        readValue = My.Computer.Registry.GetValue _
        ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ProductId", Nothing)
        TextBox7.Text = readValue ' le product id
        readValue = My.Computer.Registry.GetValue _
        ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CSDVersion", Nothing)
        TextBox8.Text = readValue ' le service pack
        readValue = My.Computer.Registry.GetValue _
("HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0", "ProcessorNameString", Nothing)
        TextBox9.Text = readValue ' le nom du processeur
        TextBox10.Text = (GetGraphicsCardName())
        TextBox12.Text = (My.Computer.Info.TotalPhysicalMemory - My.Computer.Info.AvailablePhysicalMemory) / 1024 / 1024 & "GB"
        'RAM
        Textbox13.text = getMacAddress()

    End Sub

    Private Function GetGraphicsCardName() As String ' la fonction pour la carte graph
        Dim GraphicsCardName = String.Empty
        Try
            Dim WmiSelect As New ManagementObjectSearcher("root\CIMV2", "SELECT * FROM Win32_VideoController")
            For Each WmiResults As ManagementObject In WmiSelect.Get()
                GraphicsCardName = WmiResults.GetPropertyValue("Name").ToString
                If (Not String.IsNullOrEmpty(GraphicsCardName)) Then
                    Exit For
                End If
            Next
        Catch err As ManagementException
            MessageBox.Show(err.Message)
        End Try
        Return GraphicsCardName
    End Function

    Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted

        TextBox11.Text = WebBrowser1.Document.Body.InnerText.ToString
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        MsgBox("Info PC By Darff" & Chr(13) & " " & Chr(13) & "Enjoy :)", 64, "About")
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.Close()
    End Sub

    Function getMacAddress()
        Dim nics() As NetworkInterface = _
              NetworkInterface.GetAllNetworkInterfaces 'Retrieves all network address's
        Return nics(0).GetPhysicalAddress.ToString 'This will get the actual MAC address from the address pool we generated
    End Function

    Private Function InsertChar(ByVal ch As Char, ByVal word As String, ByVal count As Integer) As String
        Dim strin As String
        Dim k As Integer
        If word.Length Mod count = 0 Then
            k = 0
        Else
            k = word.Length Mod count
        End If
        strin = String.Empty
        For iter = 0 To word.Length - 1 - k Step count
            strin &= word.Substring(iter, count) & ch
        Next
        If k = 0 Then
            Return strin.Substring(0, strin.Length - 1)
        Else
            Return strin & word.Substring(word.Length - 1 - k)
        End If

    End Function


    Dim word As String
word = InsertChar("-"c, textbox13.text, 2)
End Class
0
cs_ShayW Messages postés 3253 Date d'inscription jeudi 26 novembre 2009 Statut Membre Dernière intervention 3 décembre 2019 57
13 mars 2012 à 22:20
bien sur

Dim word As String
word = InsertChar("-"c, textbox13.text, 2)
doit etre dans une sub ou dans le sub d'un évenement à toi de savoir où appeller la fonction

Bonsoir UcFoutu
On peut surement faire plus simple
enfin chez moi faire simple c'est compliqué
0
ucfoutu Messages postés 18038 Date d'inscription lundi 7 décembre 2009 Statut Modérateur Dernière intervention 11 avril 2018 211
13 mars 2012 à 22:24
Allez, ShayW, ===>> défends les couleurs de VB.Net ===>> voilà avec les tirets (en VB6) ===>>
toto = "abracadabraetzbrasdevb6-basque"
If Len(toto) Mod 2 <> 0 Then toto = toto & " "
f = "@@-"
For i = 1 To Len(toto) \ 3
 f = f & "-" & f
Next
MsgBox Mid(Format(toto, (f)), InStr(Format(toto, (f)), Left(toto, 2)))


Transpose .
____________________
Réponse exacte ? => "REPONSE ACCEPTEE" pour faciliter les recherches d'autres forumeurs.
Pas d'aide en ligne installée ? ==> ne comptez pas sur moi pour simplement vous dire ce qu'elle contient
0
fallout81 Messages postés 11 Date d'inscription lundi 28 septembre 2009 Statut Membre Dernière intervention 15 mars 2012
13 mars 2012 à 22:44
alors j'ai placé le code (je ne sais pas si c'est bien la)http://img860.imageshack.us/img860/6867/csdse.png et cela ne fonctionne pas :/ enfin l'adresse mac n'a pas de tiret.
je peux vous uploader la source ?
0
cs_ShayW Messages postés 3253 Date d'inscription jeudi 26 novembre 2009 Statut Membre Dernière intervention 3 décembre 2019 57
13 mars 2012 à 23:01
alors j'ai placé le code (je ne sais pas si c'est bien la

c'est comme meme toi
qui écris le prog tu dois bien savoir où appeller la fonction
as tu compris ton erreur
si j'ai
class form1

private function FFF()as string
le code de FFF
end function

je ne peux pas appeller ici
dim x as string
x = FFF

End class
0
fallout81 Messages postés 11 Date d'inscription lundi 28 septembre 2009 Statut Membre Dernière intervention 15 mars 2012
13 mars 2012 à 23:19
Je ne vois pas pourquoi cela ne va pas --' je sais pas si c'est la fatigue mais la je sèche....
0
fallout81 Messages postés 11 Date d'inscription lundi 28 septembre 2009 Statut Membre Dernière intervention 15 mars 2012
14 mars 2012 à 02:00
Merci beaucoup de ton aide ça fonctionne a merveille !
0
Rejoignez-nous