🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.bazy-danych.msaccess
Article #125042

Re: własne typy danych

#125042
From: Krzysztof Naworyta
Date: Tue, 19 Aug 2008 11:27
72 lines
2534 bytes
siwy5 wrote:

| Mam zadeklarowany swój typ danych  dla uproszczenia
| firma.ulica
|
| Teraz potrzebuje odwołać się do firma.ulica gdzie ta nazwa ulica
| zaszyta jest w polu bazy
| Mogoby to wyglądać np. tak
| firma(rst.NazwaZmiennej) = "Rynek 40"
| gdzie w rst.nazwaZmiennej zaszyte jest słowo ulica
| Oczywiście to nie działa

nie działa i raczej nie zadziała.

Można własny typ danych zastapić własną klasą (choćby trywialną) z dodatkową 
właściwością Properties:

******* Class1 ****************

Option Compare Database
Option Explicit

Public a As Integer       'Twoje zmienne
Public b As Date
Public c As String


'właściwość zwracająca wartość właściwości wg jej nazwy:

Public Property Get Properties(sProperty As String) As Variant
On Error Resume Next
  Set Properties = CallByName(Me, sProperty, VbGet)
  If Err = 13 Then
     Properties = CallByName(Me, sProperty, VbGet)
     Err.cler
  End If
End Property


'właściwość ustawiająca wartość właściwości wg jej nazwy:

Public Property Let Properties(sProperty As String, NewVal As Variant)
  If IsObject(NewVal) Then
    CallByName Me, sProperty, VbSet, NewVal
  Else
    CallByName Me, sProperty, VbLet, NewVal
  End If
End Property

********************************


i teraz gdzieś w innym module:

Sub test()
  Dim x As Class1
  Set x = New Class1

  With x
    .Properties("a") = 4
    .Properties("b") = #1/1/2008#
    .Properties("c") = "Ala ma kota"

    Debug.Print x.a, x.b, x.c

  End With


End Sub

--
KN 
Technical Details
Message-ID: <g8eanc$ejh$1@news.onet.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!newsfeed.gazeta.pl!news.onet.pl!not-for-mail
References: <aa40914b-1bdb-48bd-a013-a4e439a87ccc@8g2000hse.googlegroups.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!newsfeed.gazeta.pl!news.onet.pl!not-for-mail
From: "Krzysztof Naworyta" <k.naworyta@datacomp.com.pl>
Newsgroups: pl.comp.bazy-danych.msaccess
Subject: Re: własne typy danych
Date: Tue, 19 Aug 2008 13:27:23 +0200
Organization: Onet.pl
Lines: 73
Message-ID: <g8eanc$ejh$1@news.onet.pl>
References: <aa40914b-1bdb-48bd-a013-a4e439a87ccc@8g2000hse.googlegroups.com>
NNTP-Posting-Host: azc98.internetdsl.tpnet.pl
Mime-Version: 1.0
X-Trace: news.onet.pl 1219145260 14961 83.18.132.98 (19 Aug 2008 11:27:40 GMT)
X-Complaints-To: usenet@news.onet.pl
NNTP-Posting-Date: Tue, 19 Aug 2008 11:27:40 +0000 (UTC)
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579
X-Sender: isNb2RK0ghBqVJPEt5vfjsjJSvxj2GTy
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
X-Priority: 3
X-MSMail-Priority: Normal
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit