VERSION 5.00 Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX" Begin VB.Form frmNuevoRecurso BorderStyle = 3 'Fixed Dialog Caption = "Nuevo recurso" ClientHeight = 1785 ClientLeft = 45 ClientTop = 330 ClientWidth = 5805 ControlBox = 0 'False Icon = "NuevoRecurso.frx":0000 LinkTopic = "Form1" MaxButton = 0 'False MinButton = 0 'False ScaleHeight = 1785 ScaleWidth = 5805 ShowInTaskbar = 0 'False StartUpPosition = 1 'CenterOwner Begin MSComDlg.CommonDialog CommonDialog1 Left = 120 Top = 1200 _ExtentX = 847 _ExtentY = 847 _Version = 393216 End Begin VB.CommandButton cmdAceptar Caption = "&Aceptar" Height = 375 Left = 3240 TabIndex = 7 Top = 1320 Width = 1215 End Begin VB.CommandButton cmdCancelar Cancel = -1 'True Caption = "&Cancelar" Height = 375 Left = 4560 TabIndex = 8 Top = 1320 Width = 1215 End Begin VB.CommandButton cmdFich Caption = "..." Height = 285 Left = 5400 TabIndex = 4 Top = 840 Width = 285 End Begin VB.ComboBox lstTipo Height = 315 ItemData = "NuevoRecurso.frx":058A Left = 1440 List = "NuevoRecurso.frx":058C Style = 2 'Dropdown List TabIndex = 1 Top = 120 Width = 1335 End Begin VB.TextBox txtFich Height = 285 Left = 1440 TabIndex = 3 Top = 840 Width = 3975 End Begin VB.TextBox txtID Height = 285 Left = 1440 TabIndex = 6 Top = 480 Width = 1215 End Begin VB.Label Label3 Caption = "Tipo" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 255 Left = 120 TabIndex = 0 Top = 120 Width = 1215 End Begin VB.Label Label2 Caption = "Fichero" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 255 Left = 120 TabIndex = 2 Top = 840 Width = 1215 End Begin VB.Label Label1 Caption = "ID" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 255 Left = 120 TabIndex = 5 Top = 480 Width = 1215 End End Attribute VB_Name = "frmNuevoRecurso" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit Private Const MIN_RES = 1 Private Const MAX_RES = 32000 Public bCancelar As Boolean Public bModificar As Boolean ' nuevo (False) o modificar (True) Private Sub cmdAceptar_Click() If lstTipo.Text = "" Then MsgBox "Debes seleccionar el tipo de recurso.", vbOKOnly + vbExclamation, _ "Error" Exit Sub End If If ValidaID Then bCancelar = False Me.Hide End If End Sub Private Sub cmdCancelar_Click() bCancelar = True Me.Hide End Sub Private Sub cmdFich_Click() Dim s As String, sRuta As String, sRutaAv As String If txtFich.Text <> "" Then sRuta = RutaFich(txtFich.Text) Else sRuta = App.Path End If CommonDialog1.DialogTitle = "Recurso" CommonDialog1.Filter = "Todos los archivos|*.*" CommonDialog1.InitDir = sRuta CommonDialog1.Flags = cdlOFNFileMustExist Or cdlOFNPathMustExist CommonDialog1.CancelError = True On Error Resume Next CommonDialog1.ShowOpen If Err.Number = 0 Then sRutaAv = RutaFich(sFichAventura) s = CommonDialog1.FileName ' si al principio tenemos la ruta de los ficheros de la aventura ' construimos una ruta relativa If InStr(s, sRutaAv) = 1 Then If Len(sRutaAv) < Len(s) Then s = Right(s, Len(s) - Len(sRutaAv)) End If End If txtFich.Text = s End If End Sub Private Sub Form_Load() bCancelar = False lstTipo.Clear lstTipo.AddItem RES_IMG lstTipo.AddItem RES_SND lstTipo.AddItem RES_FNT lstTipo.ListIndex = -1 End Sub ' valida el ID introducido Private Function ValidaID() As Boolean Dim i As Long On Error Resume Next i = CLng(txtID.Text) If Err.Number <> 0 Then ValidaID = False Else If i < MIN_RES Or i > MAX_RES Then ValidaID = False Else ValidaID = True End If End If If Not ValidaID Then MsgBox "El ID introducido debe ser un nº entre " & CStr(MIN_RES) & _ " y " & CStr(MAX_RES), vbOKOnly + vbExclamation, _ "Error" End If End Function ' calcula el ID correspondiente al tipo de recurso seleccionado ' coge 1 más que el más alto (MIN_RES si supera el máximo permitido o no hay recursos ' del tipo seleccionado) Private Function IDRes() As String Dim i As Long, lID As Long, lMaxRes As Long lMaxRes = -1 For i = 1 To frmRecursos.lstRes.ListItems.Count If frmRecursos.lstRes.ListItems(i).SubItems(1) = lstTipo.Text Then lID = CLng(frmRecursos.lstRes.ListItems(i).Text) If lID > lMaxRes Then lMaxRes = lID End If End If Next If lMaxRes > -1 Then IDRes = CStr(lMaxRes + 1) Else IDRes = MIN_RES End If End Function Private Sub lstTipo_Click() ' si estamos modificando no asignamos ID automáticamente If bModificar Then Exit Sub End If txtID.Text = IDRes End Sub