根据Combox

时间:2015-05-15 19:06:51

标签: excel vba combobox textbox userform

在我的Excel文档中,我在以下两列中提供了以下信息:

US Dollar (USD)                     1
British Pound (GBP)                 0.63
Guatemalan Quetzal (GTQ)            0.13
Honduras Lempira (HNL)              0.046
Other                               Please give factor
Other                               Please give factor
Other                               Please give factor
Other                               Please give factor

我有一个由第一列填充的组合框:

Private Sub UserForm_Initialize()
CurrencyList.List = Worksheets("MySheet").Range("A23:A30").Value
End Sub|

我想在下一栏中使用货币转换自动填充文本框,因此当您在组合框中选择货币时,它会自动填充文本框,以便您可以按建议保留或根据需要更改它。我在使用excel 2011的Mac上。我遇到的所有解决方案似乎都适用于Windows,我发现错误说我所谓的方法不存在。

1 个答案:

答案 0 :(得分:0)

这应该让你开始。它使用您的值(您已经使用)填充表单组合框,并且Vlookup查找与组合框中的值关联的货币。仔细检查您的ComboBox和TextBox Name属性是否与您的代码匹配。

package com.mygdx.game.network;

import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.TextInputListener;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.TextField;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
import com.badlogic.gdx.scenes.scene2d.ui.TextField.TextFieldStyle;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.shephertz.app42.gaming.multiplayer.client.WarpClient;
import com.shephertz.app42.paas.sdk.android.App42API;
import com.shephertz.app42.paas.sdk.android.App42CallBack;
import com.shephertz.app42.paas.sdk.android.user.User;
import com.shephertz.app42.paas.sdk.android.user.UserService;

public class Register implements Screen, TextInputListener
{

    private TextField usernameTxtField, passwordTxtField, confirmpassTxtField, emailTxtField;
    private TextFieldStyle txtFieldStyle;
    private BitmapFont font;
    private Stage stage;
    private Table table;
    private TextButton registerBtn;
    private TextureAtlas registerAtlas;
    private Skin registerSkin;


    @Override
    public void render(float delta) 
    {
        Gdx.gl.glClearColor(0,1,0,1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

        stage.act(delta);

        stage.draw();
    }


    @Override
    public void show() 
    {
        stage = new Stage();
        // set input processor to stage element
        Gdx.input.setInputProcessor(stage);

        table = new Table();

        table.setBounds(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

        font = new BitmapFont();
        txtFieldStyle = new TextFieldStyle();
        txtFieldStyle.fontColor = Color.RED;
        txtFieldStyle.font = font;

        // initialize new text fields
        usernameTxtField = new TextField("", txtFieldStyle);
        passwordTxtField = new TextField("", txtFieldStyle);
        confirmpassTxtField = new TextField("", txtFieldStyle);
        emailTxtField = new TextField("", txtFieldStyle);

        // set size of text fields
        usernameTxtField.setSize(100, 25);
        passwordTxtField.setSize(100, 25);
        confirmpassTxtField.setSize(100, 25);
        emailTxtField.setSize(100, 25);

        // set position of text fields
        usernameTxtField.setPosition(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2 - 50);
        passwordTxtField.setPosition(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2 - 100);
        confirmpassTxtField.setPosition(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2 - 150);
        emailTxtField.setPosition(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2 - 200);

        // passproof it
        passwordTxtField.setPasswordMode(true);
        confirmpassTxtField.setPasswordMode(true);

        // register button
        registerAtlas = new TextureAtlas("resmenu/menu/registerBtn.pack");
        registerSkin = new Skin(registerAtlas);

        // new style for exit btn
        TextButtonStyle registerButtonStyle = new TextButtonStyle();

        // when user clicks on button, load new image, when he lets go reload
        // original image
        registerButtonStyle.up = registerSkin.getDrawable("menuRegisterBtn");
        registerButtonStyle.down = registerSkin.getDrawable("menuRegisterBtnPressed");

        // off set btn
        registerButtonStyle.pressedOffsetX = 1;
        registerButtonStyle.pressedOffsetY = -1;

        registerButtonStyle.font = font;

        registerBtn = new TextButton("", registerButtonStyle);
        // add new listener
        registerBtn.addListener(new ClickListener() 
        { // fire event
            public void clicked(InputEvent event, float x, float y) 
            {
                // register account and take in user input from txt fields 
                if(usernameTxtField.getText().equals("") || passwordTxtField.getText().equals("")
                        || confirmpassTxtField.getText().equals("") || emailTxtField.getText().equals(""))
                {
                    System.out.println("fields cannot be empty");
                }
                else
                {

                    registerAccount(usernameTxtField.getText(), passwordTxtField.getText(),
                                    confirmpassTxtField.getText(), emailTxtField.getText());
                }

            }
        });

        registerBtn.pad(20);

        table.bottom();
        table.row();
        table.add(usernameTxtField);
        table.row();
        table.add(passwordTxtField);
        table.row();
        table.add(confirmpassTxtField);
        table.row();
        table.add(emailTxtField);
        table.row();
        table.add(registerBtn);
        table.debug();

        stage.addActor(table);

    }

    // register account into app42api cloud db
    public void registerAccount(String username, String password, String confirmpass, String email) 
    {
        // register account
        String CUsername = username;
        String CPassword = password;
        String CConfirmPass = confirmpass;
        String CEmail = email;

        // connect to api
        WarpClient.initialize(App42Handler.apiKey, App42Handler.secretKey);

        // build user service
        UserService userService = App42API.buildUserService();
        // create user using user input and fire callback (event)
        if (CPassword.equals(CConfirmPass)) 
        {
            userService.createUser(CUsername, CPassword, CEmail, new App42CallBack() 
            {
                public void onSuccess(Object response) 
                {
                    User user = (User) response;
                    System.out.println("successfully registered: " + user.getUserName());
                    System.out.println("email is " + user.getEmail());
                }

                public void onException(Exception ex) 
                {
                    System.out.println("Exception Message: " + ex.getMessage());
                }
            });
        }
        else 
        {
            System.out.println("Passwords need to match!!");

        }
    }

    @Override
    public void input(String text) 
    {
        // TODO Auto-generated method stub

    }

    @Override
    public void canceled() {
        // TODO Auto-generated method stub

    }

    @Override
    public void resize(int width, int height) 
    {
        // TODO Auto-generated method stub

    }


    @Override
    public void pause() {
        // TODO Auto-generated method stub

    }


    @Override
    public void resume() {
        // TODO Auto-generated method stub

    }


    @Override
    public void hide() {
        // TODO Auto-generated method stub

    }


    @Override
    public void dispose() 
    {
        stage.dispose();


    }


}