• DİKKAT

    DOSYA İndirmek/Yüklemek için ÜCRETLİ ALTIN ÜYELİK Gereklidir!
    Altın Üyelik Hakkında Bilgi

Imageye Resim Çekme

Katılım
10 Eylül 2009
Mesajlar
288
Excel Vers. ve Dili
2003 Türkçe
Forumdan derlediğim aşağıdaki kod ile C sürücüsündeki Resimler Klasöründen Image nesnesine Resim çekiyorum. Benim istediğim ComboBox1 deki isimde resim yok ise Resim1 isimli resmin görüntülenmesi.

Saygılarımla..

Kod:
Private Sub ComboBox1_Change()
Dim kls As String
kls = "C:\Resimler\"
With Application.FileSearch
    .NewSearch
    .LookIn = kls
    .Filename = ComboBox1 & ".jpg"
    .SearchSubFolders = True
    .Execute
    If .FoundFiles.Count > 0 Then
        Image1.Picture = LoadPicture(.FoundFiles(1))
    End If
End With
End Sub
 
İlgili satırı değiştirin.
Kod:
.Filename = iif( ComboBox1.text = "resim yok", "Resim1.jpg",ComboBox1 & ".jpg")
 
Merhaba,
Aşağıdaki gibi deneyin.
Kod:
Private Sub ComboBox1_Change()
Dim kls As String
kls = "C:\Resimler\"
With Application.FileSearch
    .NewSearch
    .LookIn = kls
    .Filename = ComboBox1 & ".jpg"
    .SearchSubFolders = True
    .Execute
    If .FoundFiles.Count > 0 Then
        Image1.Picture = LoadPicture(.FoundFiles(1))
Else
Image1.Picture = LoadPicture(kls&Resim1.jpg)
    End If
End With
End Sub
 
Teşekkür Ederim Sayın hamitcan ve leumruk.

Saygılarımla.
 
Alternatif olarak aşağıdaki gibi denermisiniz.

Not:ofis 2007 de Application.FileSearch çalışmaz



Private Sub ComboBox1_Change()
If ComboBox1.Text <> "" Then
resim = ComboBox1.Text
Else
resim = "Resim1"
End If
kls = "C:\Resimler\" & resim & ".jpg"
Dim ds, a
Set ds = CreateObject("Scripting.FileSystemObject")
a = ds.FileExists(kls)
If a = True Then
Image1.Picture = LoadPicture(resim)
End If

End Sub
 
Merhaba,
Aşağıdaki gibi deneyin.
Kod:
Private Sub ComboBox1_Change()
Dim kls As String
kls = "C:\Resimler\"
With Application.FileSearch
    .NewSearch
    .LookIn = kls
    .Filename = ComboBox1 & ".jpg"
    .SearchSubFolders = True
    .Execute
    If .FoundFiles.Count > 0 Then
        Image1.Picture = LoadPicture(.FoundFiles(1))
Else
[COLOR="Red"]Image1.Picture = LoadPicture(kls&Resim1.jpg)[/COLOR]
    End If
End With
End Sub

Bu satırda hata verdi.
 
Private Sub ComboBox1_Change()
If ComboBox1.Text <> "" Then
resim = ComboBox1.Text
Else
resim = "Resim1"
End If
kls = "C:\Resimler\" & resim & ".jpg"
Dim ds, a
Set ds = CreateObject("Scripting.FileSystemObject")
a = ds.FileExists(kls)
If a = True Then
Image1.Picture = LoadPicture(resim)
End If

End Sub

Halit Bey bu satırda hata verdi.
 
Private Sub ComboBox1_Change()
If ComboBox1.Text <> "" Then
resim = ComboBox1.Text
Else
resim = "Resim1"
End If
kls = "C:\Resimler\" & resim & ".jpg"
Dim ds, a
Set ds = CreateObject("Scripting.FileSystemObject")
a = ds.FileExists(kls)
If a = True Then
Image1.Picture = LoadPicture(resim)
End If

End Sub

Halit Bey bu satırda hata verdi.

kırmızı yeri aşağıdaki ile değiştiriniz.

Kod:
Image1.Picture = LoadPicture(kls)


Private Sub ComboBox1_Change()
If ComboBox1.Text <> "" Then
resim = ComboBox1.Text
Else
resim = "Resim1"
End If
kls = "C:\Resimler\" & resim & ".jpg"
Dim ds, a
Set ds = CreateObject("Scripting.FileSystemObject")
a = ds.FileExists(kls)
If a = True Then
Image1.Picture = LoadPicture(kls)
End If
End Sub
 
Halit Bey bu şekildede çalışmadı, ayrıca sayın leumruk Resim1 diğer resimlerle aynı klasörde.
 
Halit Bey bu şekildede çalışmadı, ayrıca sayın leumruk Resim1 diğer resimlerle aynı klasörde.

Combobox1 boş geçtiğiniz zaman (Resim1) adında dosyanız varmı.?
bu dosyanız yoksa tabiki hiç bir şey yapmıyacaktır .
Aşağıdaki koda uyarı mesajı ekledim dosya olmadığı zaman uyarı verecektir.

Kod:
Private Sub ComboBox1_Change()
If ComboBox1.Text <> "" Then
resim = ComboBox1.Text
Else
resim = "Resim1"
End If
kls = "C:\Resimler\" & resim & ".jpg"
Dim ds, a
Set ds = CreateObject("Scripting.FileSystemObject")
a = ds.FileExists(kls)
If a = True Then
Image1.Picture = LoadPicture(kls)
Else
MsgBox "Böyle  " & kls & "  bir resim dosyası yok"
End If
End Sub
 
Halit Bey bu şekildede çalışmadı, ayrıca sayın leumruk Resim1 diğer resimlerle aynı klasörde.

Merhaba,
Tırnak işaretini kullanmamışım. İkinci kod doğru olanı... Tekrar dener misiniz?
Kod:
Image1.Picture = LoadPicture(kls&Resim1.jpg)
Kod:
Image1.Picture = LoadPicture(kls & "Resim1.jpg")
 
Geri
Üst